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
})
}
}
原文地址:https://www.cnblogs.com/littleBit/p/8994682.html
时间: 2024-10-08 06:38:57