vue展示与隐藏侧边栏功能
navbar.vue
closeSidebar() { this.$store.commit("user/CLOSE_SIDEBAR"); },
stor中user.js
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
sidebar.vue
import { mapGetters } from "vuex"; computed: { ...mapGetters("user", ["opened"]), isCollapse() { return !this.opened; } },
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持IT俱乐部。