const state = { tags: [] } const mutations = { addTag(state, tag) { if (!state.tags.includes(tag)) { state.tags.push(tag); } }, removeTag(state, index) { state.tags.splice(index, 1); }, removeAllTags(state) { state.tags = []; }, switchTag(tag) { this.$emit('switchTag', tag); this.$router.push('/' + tag); // 添加这行代码以切换路由 } } export default { namespaced: true, state, mutations }