vue2 通过 store 传递消息
点击 723 创建时间 2024-07-14 23:37:28
store/index.js
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
export default new Vuex.Store({
state: {
category:{},
},
mutations: {
setCategory(state,ctg){
state.category = ctg;
}
},
actions: {
},
modules: {
}
})
views/category.vue
methods:{
changeCtg(ctgObj){
this.$store.commit('setCategory',ctgObj);
},
}
views/products_list.vue
export default {
computed: {
Category() {
return this.$store.state.category;
}
},
watch: {
Category(newCtg, oldCtg) {
console.log("分类发生了变化了",newCtg, oldCtg);
this.getSomeProductsFromServer(newCtg);//to do
}
},
上一篇: curl error 28 while downloading https://packagist.phpcomposer.com/packages.json: Connection timeout after 10014 ms
下一篇: 笔记:在MX linux 23.3版中添加win10引导