页面代码
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)
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…