uniapp中 使用store、修改store
uni中使用store是和vue是一样的道理,知道vue中store的使用 uni里便也是相同的方法一、在根目录创建store.js//引用Vueximport Vue from 'vue'import Vuex from 'vuex'Vue.use(Vuex)//实例store对象const store = new Vuex.Store({state: {proid: 123,},//mutat
·
uni中使用store是和vue是一样的道理,知道vue中store的使用 uni里便也是相同的方法
一、在根目录创建store.js
//引用Vuex
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
//实例store对象
const store = new Vuex.Store({
state: {
proid: 123,
},
//mutations是修改store数据入口
mutations: {
proid(state, msg) {
state.proid = msg;
},
}
})
//导出store对象
export default store
二、在main.js中全局引入store
这样就可以使用store中存的数据了
另外如果要对store中的数据进行修改如下:
//chackbtn是需要发生修改时绑定的事件
//通过commit触发store中muations里定义的方法 实现store里数据的修改
checkbtn(index,id,name){
this.$store.commit("proid",id)
},
更多推荐
所有评论(0)