我有一个标头组件已在页面中使用,由于它们在页面更改时被销毁,因此我决定将其向上移动到布局中,以便在路线更改期间,该组件持续存在(我可以制作动画/相应地进行过渡)。我正在使用VueX更新标头的内容(图像,副本等)。
现在,我在所有页面中都使用异步提取来对存储进行适当的调用(以更新或隐藏标头)。
我最终希望将提取的内容移入mixin并将其导入每个页面,而不必手动将其放置在每个页面中。问题是,我想在调用之前使用mixin来检索某些页面特定的数据。我总是可以在mixin中将其默认为默认值,但是当涉及从页面内部进行覆盖时-我无法从fetch()访问页面data()或asyncData()。
在fetch()中访问页面特定数据的最佳方法是什么?
我的混音:
export default {
data() {
return {
masthead: false
}
},
async fetch({ state }) {
await state.commit('masthead/UPDATE_MASTHEAD', this.masthead);
}
}
在页面中:从'〜/ mixins / masthead'导入标头]
export default {
name: 'homepage',
mixins: [masthead]
data() {
// Why can't I access this in fetch
return {
masthead: true
};
},
asyncData() {
// Why can't I access this in fetch?
return {
masthead: true
};
},
谢谢!