vuex用法
mutations中的方法是用来改变state中的数据
在mutations中的函数的第一个参数都是state
第二个参数是通过commit执行的时候传递过来的参数
这里的函数最多只有两个参数
actions中的函数的第一个参数都是store(new 出来的vuex的实例)
第二个参数是通过dispatch执行这个函数的是传进来的参数
最多只要两个参数
watch:{
count(newVal,oldVal){
this.$store.commit('changeCount',newVal)
}
}
computed:{
count:{
get(){
return this.$store.state.count
},
set(val){
this.$store.commit()
}
}
}
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
//这是登录模块
let loginModule = {
namespaced:true,
state:{
name:"珠峰",
},
mutations:{