1 , 在 strot ----下面 app.js
state: {
//是否是首页,默认显示小头
isHomePage:false
},
mutations: {
// 设置是否是首页的状态
setIsHomePage(state, status) {
state.isHomePage = status
}
},
2.在 router.JS index.JS里面 判断
router.afterEach(to => {
let path = to.path
if ('/home' == path ||'/' == path ||'/fxglhome' == path) {
store.commit('setIsHomePage', true)
}else {
store.commit('setIsHomePage', false)
}
setTitle(to, router.app)
// iView.LoadingBar.finish()
window.scrollTo(0, 0)
})
3,在自己的页面 main.vue
computed: {
//计算是否当前页面是首页,用来替换头部内容区域
homeHeader() {
return this.$store.state.app.isHomePage
}}
网友评论