【发布时间】:2018-11-21 03:36:06
【问题描述】:
好的,我正在尝试找到将当前用户加载到我的 vue 应用程序中的最佳方法,以便我可以从任何其他组件或路由中提取用户名和 ID。
现在我已经尝试过了:
app.js
new Vue({
el: '#app',
computed: {
user(data) {
return new Promise((resolve, reject) => {
axios.get('/current-user')
.then(response => {
resolve(response.data);
console.log(response.data);
})
.catch(error => {
reject(error.response.data);
});
});
}
},
router
});
它会很好地记录我的用户,但我不能在任何刀片文件中调用@{{ user }}。我应该如何让当前用户进行应用初始化?
【问题讨论】: