//moguyun
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    //存放全局共享数据
    count:0
  },
  getters: {
    showNum(state){
      let newcount = state.count *2
      return '测试getters,更新的数量为count*2: '+ newcount
    },
    showNum1(state){
      let newcount = state.count *3
      return '测试getters,更新的数量为为count*3: '+ newcount
    }
  },
  mutations: {
    //变更store中的数据
    add(state){
      state.count++
    },
    addN(state,step){
      state.count+=step
    },
    sub(state){
      state.count--
    },
    subN(state,step){
      state.count-=step
    },
    xc(state,step){
      state.count=state.count * step
    }
  },
  actions: {
    addAsync(context){
      setTimeout(()=>{
        context.commit('add')
      },1000)
    },
    addNAsync(context,step){
      setTimeout(()=>{
        context.commit('addN',step)
      },1000)
    },
    subNAsync(context,step){
      setTimeout(()=>{
        context.commit('subN',step)
      },1000)
    }
  },
  modules: {
  }
})
