1.store/index.js
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
export default new Vuex.Store({
state: {
count:0
},
mutations: {
},
actions: {
},
modules: {
}
})
2.引入mapstate
import { mapState } from 'vuex'
3.动态加载数据
computed: {
...mapState(['count'])
}
4.显示数据
<h3>当前最新的count值为:{{count}}</h3>