我需要设置一些从组件到商店的数据
methods: { // my component
...mapMutations('lists', ['setContactListName']),//import function from the store
viewHandler (id, item) { // hadler
this.$router.push(`/company/sample-contact/${id}`);
this.setContactListName(item); // pass data to the function
}
}
state() { // store
return {
contactListName: {}
};
},
mutations:{
setContactListName (state, payload) {// handler
state.contactListName = payload;
}
}
我单击后什么也没有发生,即使控制台中没有错误
答案 0 :(得分:1)
methods: { // my component
...mapMutations(['setContactListName']), //import function from the store
viewHandler(id, item) { // hadler
this.$router.push(`/company/sample-contact/${id}`);
this.setContactListName(item); // pass data to the function
}
}
或使用 this。$ store.commit
methods: { // my component
viewHandler(id, item) { // hadler
this.$router.push(`/company/sample-contact/${id}`);
this.$store.commit('setContactListName', item);
}
}