美文网首页
创建store改变VUEX

创建store改变VUEX

作者: 四哥_d0ad | 来源:发表于2018-11-14 21:12 被阅读0次

    import Vue from "vue";

    import Vuex from "vuex";

    Vue.use(Vuex);

    //创建一个store对象

    const store=new Vuex.Store({

    //用来存放数据的对象

    state:{

    title:"卖座电影",

    username: '',

    code: '',

    islogin: false

    },

    //定义取数据

    getters:{

    title:function(state){

    return state.title;

    },

    username: state => state.username,

    userId: state => state.userId,

    islogin: state => state.islogin

    },

    mutations:{

    updateTitle:(state,payload)=>{

    state.title=payload;

    },

    upUsername: (state, payload) => {

    state.username = payload

    },

    upId: (state, payload) => {

    state.userId = payload

    },

    upIslogin: (state, payload) => {

    state.islogin = payload

    },

    }

    });

    export default store;

    相关文章

      网友评论

          本文标题:创建store改变VUEX

          本文链接:https://www.haomeiwen.com/subject/lbssfqtx.html