路线中有一种简单的方法,所以我可以在Ember 2中测试加载子状态
我试过这个,但它不起作用。在原始路线中,我有:
actions: {
willTransition(transition) {
this.sleep(5000);
}
},
sleep(time) {
return new RSVP.Promise((resolve) => setTimeout(resolve, time));
}
答案 0 :(得分:1)
要查看加载子状态,
model() {
return new RSVP.Promise((resolve, reject) => {
Ember.run.later(() => {
resolve("failed to load application model");
}, 500);
});
}
要查看错误加载子状态,
model() {
return new RSVP.Promise((resolve, reject) => {
Ember.run.later(() => {
reject(
new Error('failed to load application model')
);
}, 500);
});
}
您应该显示相应的hbs文件。参考ember官方指南。 https://guides.emberjs.com/v2.8.0/routing/loading-and-error-substates/