How to get the user info to the “data” part of the app in vue.js?

a 夏天 提交于 2019-12-01 13:08:23

In Vue, the state (aka data properties) is initialized between the beforeCreate and created hooks.

So any change you do to data in beforeCreate is lost.

Change your hook to created

created() {                         // changed this line
  this.$store.dispatch('setUser');
  let user = this.$store.getters.getUser;
  console.log(user); // this works!!!
  this.$set(this.user, 'uid', user.uid)
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!