vuex

作者: 一名有马甲线的程序媛 | 来源:发表于2018-07-04 15:37 被阅读10次

    安装、使用 vuex

    首先我们在 vue.js 2.0 开发环境中安装 vuex :

    npm install vuex --save
    

    然后 , 在 main.js 中加入 :

    import vuex from 'vuex'
    Vue.use(vuex);
    var store = new vuex.Store({//store对象
        state:{
            show:false
        }
    })
    

    再然后 , 在实例化 Vue对象时加入 store 对象 :

    new Vue({
      el: '#app',
      router,
      store,//使用store
      template: '<App/>',
      components: { App }
    })
    

    完成到这一步 , 上述例子中的 $store.state.show 就可以使用了。

    相关文章

      网友评论

          本文标题:vuex

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