uniapp | 使用Vuex

Vuex

store/index.js
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
    state: {
        isLoginStatus:false,        //  用户登陆状态
        userFind:{},                //  用户信息
    },
    // 
    mutations: {
        demo(state,value) {
            console.log('demo')
            
        },
        
        login(state, provider) {
            console.log(state)
            console.log(provider)
            state.login = true;
            state.token = provider.token;
            state.userName = provider.userName;
            state.avatarUrl = provider.avatarUrl;
        },
        logout(state) {
            state.login = false;
            state.token = '';
            state.userName = '';
            state.avatarUrl = '';
        }
    }
})
export default store

使用

{{userFind.nick_name?userFind.nick_name:'暂无'}}

export default {
        computed:{
            userFind(){
                return this.$store.state.userFind
            },
        },

你可能感兴趣的:(uniapp | 使用Vuex)