首先成功运行vue-cli项目
安装vuex
npm instal i vuex –save
修改配置文件
store
新建文件夹store(与router同级)
然后在store目录下新建index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
export default new Vuex.Store({
strict: process.env.NODE_ENV !== 'production',
modules: {
},
getters: {
},
actions: {
},
});
|
main.js
1
2
3
4
5
6
7
8
9
10
| import Vue from 'vue'
import router from './router'
import store from './store'
Vue.config.productionTip = false
/* eslint-disable no-new */
new Vue({
router,
store
}).$mount('#app')
|
index.html
1
2
3
4
5
6
7
8
9
10
11
12
| <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>vue-cli</title>
</head>
<body>
<div id="app">
<router-view></router-view>
</div>
</body>
</html>
|