如何在beforeEnter中访问通过商店操作异步检索的商店数据?
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
}
}
}
Run Code Online (Sandbox Code Playgroud)
这在第一页加载或页面重新加载之后,获取初始化数据并且路由器需要等待该数据允许用户访问该页面时尤为重要.
路由器是否可以"等待"获取数据?或者,与异步vuex商店数据相结合处理导航防护的最佳方法是什么?
(哦和预填充"asyncData"不能解决,因为beforeEnter挂钩需要从数据库做出真实数据的决定,而不是默认数据)