2024年06月18日 建站教程
利用Vuex,将 state 定义在 store 中,组件通过 dispatch mutation 的方式操作 state。下面web建站小编给大家简单介绍一下具体实现代码!
具体代码示例如下:
js
// store
state: { count: 0 }
// 组件 1
methods: {
increment() {
this.$store.commit('increment')
}
}
// 组件 2
computed: {
count() {
return this.$store.state.count
}
}
本文链接:http://so.lmcjl.com/news/6790/