<span @click="closeSidebar" class="sidebar"> <svg-icon :icon-class="'sidebar'" :class="{ changeCollapse: isCollapse }"/> </span>
closeSidebar() { this.$store.commit("user/CLOSE_SIDEBAR"); },
const user = { namespaced: true, state: { opened: localStorage.getItem('sidebarStatus') ? !!+localStorage.getItem('sidebarStatus') : true, }, mutations: { CLOSE_SIDEBAR: (state) => { state.opened = !state.opened if (state.opened) { localStorage.setItem('sidebarStatus', 1) } else { localStorage.setItem('sidebarStatus', 0) } }, }, getters: { opened: state => state.opened } } export default user
<el-menu :default-active="defaultActive" class="el-menu-vertical-demo" background-color="#3C4A78" :active-text-color="isCollapse ? '#fff' : '#3C4A78'" text-color="#F6F8FF" unique-opened :collapse="isCollapse" :collapse-transition="false" > </el-menu>
import { mapGetters } from "vuex"; computed: { ...mapGetters("user", ["opened"]), isCollapse() { return !this.opened; } },
以上为个人经验,希望对您有所帮助。