仓库:vuex

仓库配置:store.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex);

export default new Vuex.Store({
// 全局可以访问的变量 - 获取值
// 组件内:this.$store.state.title
state: {
title: '主页'
},
// 全局可以访问的方法 - 修改值
// 组件内:this.$store.commit('updateTitle', '新值')
mutations: {
updateTitle (state, newValue) {
state.title = newValue
}
},
actions: {}
})