vuex Configuration

import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import Vuex from 'vuex'

 Vue.use(Vuex)
 const myStore = new Vuex.Store({
    state :{
      count:0
    },
    getters:{
       getCount(state){
            return '当前最新的count值是:'+state.count
       }
    },
    mutations:{
       add(state){
          state.count++
       }
    },
    actions:{
        mody(e){
            setTimeout( ()=>{
              e.commit('add')
            },2000 )
        }
    }
    
})

Vue.config.productionTip = false

new Vue({
  router,
  store:myStore,
  render: h => h(App)
}).$mount('#app')

 

Guess you like

Origin www.cnblogs.com/javascript9527/p/11504270.html