页面代码methods: {
...mapActions(['addList', 'delList']), add (value) { this.addList({title: value})
},
del (item) { this.delList(item)
}
}actions中代码import * as types from './mutations'export const addList = ({commit}, item) => {
commit(types.ADD_LIST, item)
}
export const delList = ({commit}, item) => {
commit(types.DELETE_LIST, item)
}但是执行会报[vuex] Expects string as the type, but found function.求高手指点一下哪里出错了,非常感谢.如果把上面代码改为下面的代码就可以执行methods: { add (value) { this.$store.commit('ADD_LIST', {title: value})
},
del (item) { this.$store.commit('DELETE_LIST', item)
}
}
1 回答
冉冉说
TA贡献1877条经验 获得超1个赞
methods: {
add (value) {
this.$store.commit('ADD_LIST', {title: value})
},
del (item) {
this.$store.commit('DELETE_LIST', item)
}
}
问一下,你说这段代码可以执行达到效果,那为什么不是this.$store.commit(types.DELETE_LIST, item)
?
你actions.js中都用了types,是不是mutation-types.js
文件出了问题呢?
添加回答
举报
0/150
提交
取消