1. 程式人生 > >在Vue中如何新增全域性store

在Vue中如何新增全域性store

1.在命令列中輸入安裝

npm install --save vuex

2.然後在main.js檔案中引用store和在new Vue中宣告store

import store from './store'

store,

3.在src中建立一個page檔案,在page檔案下建立一個module的js檔案(內容如下)

const state = {

  HomeStatus:{

    LoginStatus:false

  },

  Users:[],

}

 

const mutations = {

  ['setuseinfo'] (state, data) {

 

  },

}

 

const actions = {

 

}

4.在src下建立一個store檔案,在store檔案下建立一個index的js檔案

import Vue from 'vue'
import Vuex from 'vuex'
import page from '../page/module'
Vue.use(Vuex)

export default new Vuex.Store({
state: {}
}