美文网首页
Vuex 配置

Vuex 配置

作者: 全汪汪 | 来源:发表于2019-12-12 16:19 被阅读0次

    1.使用npm 安装
    npm install vuex --save
    2.配置main.js

    import Vuex from 'vuex'
    Vue.use(Vuex)
    

    3.新建一个store仓库

    const store = new Vuex.Store({
      state: {
        count: 0
      },
      mutations: {
        increment (state) {
          state.count++
        }
      }
    })
    

    4.引用到自己的Vue示例中

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

    5.在组件中引用
    通过this.$store 其中$store为自己定义store仓库的名字

    参考
    https://www.jianshu.com/p/8c97cfe42475

    相关文章

      网友评论

          本文标题:Vuex 配置

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