0
TL; DR:什么是启动应用程序之前做异步的东西的好方法? 如果我在创建/装载根Vue实例之前等待异步内容完成,vue-devtools无法正常工作。如何在安装根Vue实例之前获取数据?
我是Vue.js的新手,我正在开发一个后台应用程序,除非用户登录,否则什么都不可访问。除了登录/注册页面当然。因此,在页面加载
我做这样的事情:
// Set up store and router ...
router.beforeEach(function (to, from, next) {
/* redirect to auth if store.state.auth.isLogged is false */
}
// Dispatch an action that send a request to the API to get the connected user
// (or null if the user is not logged)
store.dispatch('getAuth').then(user) {
// Mount the app one the request is done and the mutation for isLogged is done
new Vue({
el: '#app',
router,
store,
// ...
});
}
在我的index.html我有一个纯HTML/CSS加载页面,等待VUE应用装载。
所以这工作正常,在加载时,应用程序检查用户是否登录,一旦完成,它会重定向到auth页面,如果需要的话。
我的问题主要是vue-devtools,看起来如果在页面加载时未挂载根Vue实例,我无法从vue-devtools检查组件,但vuex &事件检查工作正常。再加上铬上的扩展名图标变灰(“Vue.js未检测到”),而它的作品。
我做错了什么?或者它是devtools的问题?
谢谢你的工作!我没有注意到按钮 – SebT