vue store获取值时 Computed property "activeTag" was assigned to but it has no setter.

出现原因:
  element-ui中 el-tab绑定的值在切换tab时会自动修改
  而activeTag是从store中获取的值,不能直接修改
  要添加给它绑定上set  
 
activeTag" type="card" closable @tab-click="handleClick" @tab-remove="handleRemove">
  
    :key="item.id"
    v-for="item in tags"
  >
  
 
报错情况
computed: {
  ...mapState({
    tags: state => state.tags,
    activeTag: state => state.activeTag
  }),
}
 
修改后:
computed: {
  ...mapState({
    tags: state => state.tags,
  }),
  activeTag: {
    get () {
      return this.$store.state.activeTag;
    },
    set (val) {
      this.$store.dispatch('changeActiveTag', val);
    }
  }
},

你可能感兴趣的:(vue store获取值时 Computed property "activeTag" was assigned to but it has no setter.)