出现原因:
element-ui中 el-tab绑定的值在切换tab时会自动修改
而activeTag是从store中获取的值,不能直接修改
要添加给它绑定上set
<el-tabs class="tags" v-model="activeTag" type="card" closable @tab-click="handleClick" @tab-remove="handleRemove">
<el-tab-pane
:key="item.id"
v-for="item in tags"
>
</el-tab-pane>
</el-tabs>
报错情况
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);
}
}
},