vuex管理頁面標題
阿新 • • 發佈:2018-05-05
log nav ont 標題 ret spa tor console urn 1、在
2、新增文件
1、在store
-> mutation-types.js
文件新增常量
export const UPDATE_TITLE = ‘UPDATE_TITLE‘
2、新增文件title.js
目錄結構如下 store
->moudules
->title.js
import * as types from ‘../mutation-types‘ //state export const state = { navigationTitle : ‘‘ } //mutation export const mutations = { [types.UPDATE_TITLE](state,title){ Object.assign(state, { ...payload }) console.log(state.navigationTitle) } } //actions export const actions = { saveTitle({commit, dispatch}, payload) { commit(types.UPDATE_TITLE, payload) }, } //getters export const getters = { localTitle: state => { return { ...state } } }
3、標題組件
<div>{{localTitle.navigationTitle}}</div>
export default {
computed:{
...mapGetters([
‘localTitle‘
])
},
}
4、各個頁面
export default { mounted(){ this.$store.dispatch(‘saveTitle‘,{ navigationTitle:this.title }) } }
vuex管理頁面標題