如何访问beforeStore中通过store操作异步获取的存储数据?
import store from './vuex/store';
store.dispatch('initApp'); // in here, async data will be fetched and assigned to the store's state
// following is an excerpt of the routes object:
{
path: '/example',
component: Example,
beforeEnter: (to, from, next) =>
{
if (store.state.asyncData) {
// the above state is not available here, since it
// it is resolved asynchronously in the store action
}
}
}
这对于首次加载页面或重新加载页面后尤为重要,因为当正在读取初始数据并且路由器需要等待该数据以允许用户访问或不访问该页面时。
路由器是否有可能“等待”要提取的数据?或者结合异步vuex存储数据处理导航卫士的最佳方法是什么?
(哦,并且预先填充“ asyncData”不是解决方案,因为beforeEnter挂钩需要根据数据库中的实际数据(而非默认数据)做出决定)