金狮镖局 Design By www.egabc.com
废话不说,上代码!
<a-menu theme="dark" mode="inline" :selectedKeys="[$route.path]"> <a-menu-item :key="'/home'"> <router-link to="home"> <a-icon type="user" /> <span>nav 1</span> </router-link> </a-menu-item> <a-menu-item :key="'/about'"> <router-link to="about"> <a-icon type="video-camera" /> <span>nav 2</span> </router-link> </a-menu-item> <a-menu-item :key="'/123123'"> <router-link to="123123"> <a-icon type="upload" /> <span>nav 3</span> </router-link> </a-menu-item> </a-menu>
重点:
1,selectedkeys要设置成$route.path地址
2,a-menu-item 的key设置成要去的地址
刷新页面,成功!
补充知识:vue根据路由刷新页面(切换菜单刷新页面)
刷新页面有两种方法:
一种是用:localtion.reload();但是这种是重新加载页面,造成一闪一闪的效果。
一种是用provide+inject,
provider/inject:简单的来说就是在父组件中通过provider来提供变量,然后在子组件中通过inject来注入变量。
需要注意的是这里不论子组件有多深,只要调用了inject那么就可以注入provider中的数据。而不是局限于只能从当前父组件的prop属性来获取数据。
1.在app.vue页面中加入
<div id="app"> <router-view v-if="isRouterAlive"></router-view> </div>
provide() { return{ reload: this.reload } }, data() { return { isRouterAlive: true } }, methods: { reload () { this.isRouterAlive = false; this.$nextTick(function () { this.isRouterAlive = true }) } },
2.在菜单页面加入
inject: ['reload'], // 注入重载的功能(注入依赖) watch: { //检测路由参数发生改变时,刷新当前页面 调用 '$route': function(){ // this.reload(); } },
3.注意这个@click方法,里面就是调用重新加载的方法
<el-menu-item v-if="validatenull(item[childrenKey]) && vaildRoles(item)" :index="item[pathKey]" @click="open(item)" :key="item[labelKey]" :class="{'is-active':vaildAvtive(item)}" >
调用this.reload()方法,即可重新加载路由刷新页面。
open(item) { if (this.screen <= 1) this.$store.commit("SET_COLLAPSE"); this.$router.$avueRouter.group = item.group; this.$router.push({ path: this.$router.$avueRouter.getPath({ name: item[this.labelKey], src: item[this.pathKey] }), query: item.query, }); this.reload(); },
以上这篇antd vue 刷新保留当前页面路由,保留选中菜单,保留menu选中操作就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
金狮镖局 Design By www.egabc.com
金狮镖局
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
金狮镖局 Design By www.egabc.com
暂无antd vue 刷新保留当前页面路由,保留选中菜单,保留menu选中操作的评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
2024年09月28日
2024年09月28日
- 纪钧瀚《钢琴阅读时光 雨中书店聆听轻音乐》[FLAC/分轨][399.62MB]
- 证声音乐图书馆《走向自然 疗心爵士乐》[320K/MP3][87.4MB]
- 证声音乐图书馆《走向自然 疗心爵士乐》[FLAC/分轨][184.94MB]
- 陈慧娴.2018-Priscilla-Ism演唱会3CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 郑秀文.1999-我应该得到(国)【华纳】【WAV+CUE】
- 陈家慧.2011-钢琴酒吧2CD【龙吟唱片】【WAV+CUE】
- 证声音乐图书馆《雨季 蓝调吉他 Rainy Blues》[320K/MP3][45.01MB]
- 证声音乐图书馆《雨季 蓝调吉他 Rainy Blues》[FLAC/分轨][109.13MB]
- 赞多《序章》[320K/MP3][45.54MB]
- 许巍.2004-每一刻都是崭新的【步升大风】【WAV+CUE】
- 群星.2024-四方馆影视原声带【韶愔音乐】【FLAC分轨】
- 陈雷.1997-安锁咧【金圆唱片】【WAV+CUE】
- 关淑怡.2013-MY.FAVORITE.SK.3CD【环球】【WAV+CUE】
- Sweety.2006-花言乔语【丰华】【WAV+CUE】
- 李恕权.2003-回·20年全精选2CD【SONY】【WAV+CUE】