美文网首页
vue-cli中使用vuex

vue-cli中使用vuex

作者: 皇甫圣坤 | 来源:发表于2019-03-13 09:34 被阅读0次

1.安装

$ npm install --save vuex
$ yarn add vuex

2. 创建store.js

3. 在store.js 中引入vue 以及vuex

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

4. 创建 store

const store = new Vue.Store({
  //配置
})

5. 导出 store

export default store

6. 在main.js中导入store并且写在new Vue中

  import store from '路径'
    new Vue ({
      store
    })

2. 辅助函数一共有四个

mapState mapGetters mapMutations mapActions
这四个函数实现不了新的功能,只能让代码更简洁
(降低代码耦合)
辅助函数只能在Vue-cli中使用

相关文章

网友评论

      本文标题:vue-cli中使用vuex

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