const store = new Vuex.Store({
state: {
hasLogin: false,
userInfo: {}
},
mutations: {
login(state, provider) {
state.hasLogin = true;
state.userInfo = provider;
uni.setStorage({ //缓存用户登陆状态
key: ‘userInfo’,
data: provider
})
},
logout(state) {
state.hasLogin = false;
state.userInfo = {};
uni.removeStorage({
key: ‘userInfo’
})
}
},
actions: {
}
})
export default store
然后在main.js中引用挂载
import Vue from ‘vue’
import App from ‘./App’
impo 《大厂前端面试题解析+Web核心总结学习笔记+企业项目实战源码+最新高清讲解视频》无偿开源 徽信搜索公众号【编程进阶路】 rt store from ‘./store’
Vue.config.productionTip = false
Vue.prototype.$store = store
App.mpType = ‘app’
const app = new Vue({
store,
…App
})
app.$mount()
在页面中使用
在script中引入