indes.js页面

import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    sidebar: false, //全局导航缩起
  },
  getters
})

export default store

设置页面

hideNav(){
  this.$store.state.sidebar = true;
}

监听页面

//监控vue实例的变化
watch: {
    navHide: function(old,new) {
        console.log(old);
    }
},
//监控定义的变量
computed: {
    navHide(){
        return this.$store.state.sidebar;
    },
},