cnpm install vuex --save
D:workspacexxxsrcmain.js
import Vuex from 'vuex' Vue.use(Vuex) let store = new Vuex({ state: { totalPrice: 0 }, mutations: { increment (state, price) { state.totalPrice += price }, decrement (state, price) { state.totalPrice -= price } } })
new Vue({ el: '#app', router, store, template: '<App/>', components: { App } })
使用
this.$store.state.totalPrice