1. 官方文档地址
安装 | VuexVue.js 的中心化状态管理方案https://v3.vuex.vuejs.org/zh/installation.html
2. 安装插件
npm i vuex@3.x -S
npm i vuex@3.x -S --registry=http://registry.npmmirror.com
3.使用插件
import Vuex from 'vuex'
Vue.use(Vuex)
4. 基础语法
const store = new Vuex.Store({
state: {
count: 0
},
mutations: {
increment (state) {
state.count++
}
}
})
new Vue({
…
store
}).$mount('#app')