zoukankan      html  css  js  c++  java
  • Vue安装vuex

    1.安装:

      进入项目路径后,在项目终端输入:npm install vuex --save   或者  cnpm install vuex --save

    2.安装完成后,会在项目的package.json文件中显示vuex插件,如下:

      "dependencies": {
        "vue": "^2.5.2",
        "vue-router": "^3.0.1",
        "vuex": "^3.3.0"
      },

     3.再项目src目录中新建store.js,文件内容如下:

    import Vue from 'vue'
    import Vuex from 'vuex'
    
    Vue.use(Vuex);
    
    export default new Vuex.Store({
        //所有的数据都放在state中
        state:{},
    
        //操作数据,唯一的通道是mutations
        mutations:{},
    
        //actions,可以来做异步操作,然后提交给mutations,而后再对state(数据)进行操作
        actions:{}
    })

    4.在main.js中应用vuex:

      导入store,然后再new Vue中使用,代码如下:

    // The Vue build version to load with the `import` command
    // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
    import Vue from 'vue'
    import App from './App'
    import router from './router'
    import store from './store'   //导入store
    
    Vue.config.productionTip = false
    
    /* eslint-disable no-new */
    new Vue({
      el: '#app',
      router,
      store,   //在new Vue中使用
      components: { App },
      template: '<App/>'
    })


    https://blog.csdn.net/qq_41999617/article/details/84635325

    https://www.cnblogs.com/songrimin/p/7815850.html

  • 相关阅读:
    Win搭建JAVA环境
    Python JSON存储数据
    XML
    模块5
    模块4
    模块3
    模块2
    模块
    开放封闭原则
    函数续
  • 原文地址:https://www.cnblogs.com/jingzaixin/p/12814194.html
Copyright © 2011-2022 走看看