此处tab是自定义的文件
- import Vue from "vue"
- import Vuex from "vuex"
- import tab from "./tab"
-
- Vue.use(Vuex)
-
- export default new Vuex.Store({
- modules:{
- tab
- }
- })
- export default {
- state: {
- isCollapse: false, //控制菜单展开或收起
- },
- mutations: {
- //修改菜单展开收起的方法
- collapseMenu(state) {
- state.isCollapse=!state.isCollapse
- },
- },
- };
- import Vue from 'vue'
- import App from './App.vue'
- import ElementUI from 'element-ui';
- import 'element-ui/lib/theme-chalk/index.css';
-
- import router from './router';
-
- import store from "./store"
-
- Vue.use(ElementUI);
-
- Vue.config.productionTip = false
-
- new Vue({
- router,
- store,
- render: h => h(App),
- }).$mount('#app')
5.1在哪里更改状态
-
- <el-button @click="handleMenu" icon="el-icon-menu" size="mini">el-button>
- methods:{
- handleMenu()
- {
- this.$store.commit("collapseMenu")
- }
5.2在哪里使用状态
- <el-menu
- :collapse="isCollapse"
- >
- computed: {
- isCollapse()
- {
- return this.$store.state.tab.isCollapse
- }
- },