vue.js vuex vue-router

2017-07-06  本文已影响17人  小小小胡

PS:

                                             这只是个人笔记

                                                  这只是个人笔记

                                                               这只是个人笔记

使用vue-cli脚手架安装vue项目  vue init webpack project  

npm install vuex --save 

在src 中新建项目为store > index.js | modules>app.js

在index.js中

import Vue from 'vue';

import Vuex from 'vuex';

import app from './modules/app.js'

Vue.use(Vuex);

const store = new Vuex.Store({

modules:{

app,

}

});

export default store;

而在modules中的文件返回的时候需要注意,需要加上 export default{}

const state = {

msg : 'hello vue'

}

export default {

state

};

而在其他组建中使用store的时候 this.$store.state.app.ms

上一篇 下一篇

猜你喜欢

热点阅读