第一种方式:
methods: {
...mapMutations(['addMenu']),
clear() {
let name = 'text'
let etn = 'scc';
let two = 'try';
// 一个参数
this.addMenu(one);
// 多个参数
this.addMenu({one,two});
}
}
第二种方式:
methods: {
this.$store.commit("addMenu",{name:'text', two:'try', etn:'scc'})
}
第三种方法:
this.$store.commit({
type:"addIncrement",
two:'try',
etn:'scc',
name:'text',
})
store/index.js
mutations: {
//一个参数
addMenu(state,val){
consloe.log(val) // text
}
// 多个参数
addMenu(state,val){
consloe.log(val.name) // text
consloe.log(val.etn) // scc
}
}