数据在一个页面上的多个 Aurelia 应用程序之间移动
Data moving between multiple Aurelia apps on one page
根据问题,Aurelia 中有没有办法让同一页面上的两个应用程序异步工作,这类似于 Aurelia .two-way
视图中两个不同视图模型的方法。
例如:
在应用程序 A 中,我使用 .post
方法和 aurelia-http-client
来传递 this.data = {"data": this.item};
,其中 item
绑定到文本输入。在 return 中,我从 API 得到 containerId
。现在在应用程序 B 中,我想使用相同的 containerId
和 .get
方法来获取 data
在应用程序 A 中发布。
稍后我想通过 .put
方法异步使用应用程序 A 和应用程序 B,这意味着每当我使用应用程序 A 更新数据时,它都会在应用程序 B 中自动更新。
您可以创建一个“共享状态”模块(或多个模块)并根据需要导入它们。
Here's a working plunker
代码如下:
共享-state.js
export var sharedState = {
foo: 'foo',
bar: 'bar',
baz: 'baz'
};
app1.js
import {sharedState} from './shared-state';
export class App {
name = 'App 1';
state = sharedState;
}
app2.js
import {sharedState} from './shared-state';
export class App {
name = 'App 2';
state = sharedState;
}
根据问题.two-way
视图中两个不同视图模型的方法。
例如:
在应用程序 A 中,我使用 .post
方法和 aurelia-http-client
来传递 this.data = {"data": this.item};
,其中 item
绑定到文本输入。在 return 中,我从 API 得到 containerId
。现在在应用程序 B 中,我想使用相同的 containerId
和 .get
方法来获取 data
在应用程序 A 中发布。
稍后我想通过 .put
方法异步使用应用程序 A 和应用程序 B,这意味着每当我使用应用程序 A 更新数据时,它都会在应用程序 B 中自动更新。
您可以创建一个“共享状态”模块(或多个模块)并根据需要导入它们。
Here's a working plunker
代码如下:
共享-state.js
export var sharedState = {
foo: 'foo',
bar: 'bar',
baz: 'baz'
};
app1.js
import {sharedState} from './shared-state';
export class App {
name = 'App 1';
state = sharedState;
}
app2.js
import {sharedState} from './shared-state';
export class App {
name = 'App 2';
state = sharedState;
}