[Vue warn]: Computed property "userInfo" was assigned to but it has no setter.

一、报错信息

[Vue warn]: Computed property “userInfo” was assigned to but it has no setter.

二、报错代码

computed: {
  ...mapState({
    userInfo: state => state.userInfo
  })
},
methods: {
  ...mapActions(['setUserInfo']),
  getPersonInfo () {
    this.$axios.get('userinfo/').then(res => {
      if (res.data.flag) {
        this.userInfo = res.data.data // 这句代码应该删除掉
        this.setUserInfo(res.data.data)
      }
    })
  }
}

三、报错原因

对在computed中值进行了赋值操作

四、解决办法

删除掉对computed中的值的赋值操作

this.userInfo = res.data.data // 这句代码应该删除掉
Logo

前往低代码交流专区

更多推荐