python web全栈,  python全栈,  前端开发

13用户列表-在sessionStorage 中保存激活的菜单

菜单属性default-active

  • 关键代码块
<!--菜单属性-->
<el-menu :default-active="activePath">
 <!--default-active默认的激活菜单-->
<!--二级菜单添加click事件saveNavState-->
<el-menu-item :index="'/' + subItem.path" v-for="subItem in item.children" :key="subItem.id"
                        @click="saveNavState('/' + subItem.path)">
                            <template slot="title">
                                <!-- 图标 ,将二级图标设置成menu-->
                                <i class="el-icon-menu"></i>
                                <!-- 文本 -->
                                <span>{{subItem.authName}}</span>
                           </template>
</el-menu-item>

//初始化activePath
data() {
            return{
                //被激活的连接地址
                activePath: '',

            }
        },
// 默认加载sessionStorage中的activePath
created() {
            this.getMenuList();
            //获取默认的激活连接
            this.activePath = window.sessionStorage.getItem('activePath')
        },

methods: {
            //保存连接的激活状态
            saveNavState(activePath) {
                window.sessionStorage.setItem('activePath', activePath);
                //切换后要记得保存状态值
                this.activePath = activePath
            }

        }
    }

file

留言

您的电子邮箱地址不会被公开。 必填项已用*标注

闽ICP备20008591号-1