vue项目下vuex的配置

1 minute read

首先成功运行vue-cli项目

安装vuex

npm instal i vuex –save

修改配置文件

store

新建文件夹store(与router同级) 然后在store目录下新建index.js

 1import Vue from 'vue';
 2import Vuex from 'vuex';
 3
 4Vue.use(Vuex);
 5export default new Vuex.Store({
 6  strict: process.env.NODE_ENV !== 'production',
 7  modules: {
 8
 9  },
10  getters: {
11
12  },
13  actions: {
14
15  },
16});

main.js

 1import Vue from 'vue'
 2import router from './router'
 3import store from './store'
 4
 5Vue.config.productionTip = false
 6/* eslint-disable no-new */
 7new Vue({
 8  router,
 9  store
10}).$mount('#app')

index.html

 1<!DOCTYPE html>
 2<html>
 3  <head>
 4    <meta charset="utf-8">
 5    <title>vue-cli</title>
 6  </head>
 7  <body>
 8  <div id="app">
 9    <router-view></router-view>
10  </div>
11  </body>
12</html>