1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > vue刷新页面及路由跳转到同一页面的刷新问题

vue刷新页面及路由跳转到同一页面的刷新问题

时间:2021-03-06 19:35:43

相关推荐

vue刷新页面及路由跳转到同一页面的刷新问题

一、直接刷新当前页面的方法

this.$router.go(0)

二、路由跳转到同一页面不刷新(页面内的路由跳转)

下面展示了一个vue组件的跳转逻辑,通过router-view的key不断更新,确保每次跳转到的路由好像是不一样的,实现每次进行路由跳转都会刷新。这样写在性能上可能有一些问题(未验证)

<template><el-aside id="isshow"><router-view :key="key"></router-view></el-aside></template><script>export default {computed: {key() {//解决同一组件路由跳转,数据不刷新问题return this.$route.name !== undefined? this.$route.name +new Date(): this.$route +new Date()}},//某函数中需要跳转位置的写法this.$router.replace({name: 'xqdmRightForm',params:{ val:null ,change_id: '000'+new Date().getSeconds() ,type: 'add'}});</script>

上述路由跳转的代码中参数change_id的作用是让每次跳转过去的路由路径不同,通过路由定义时的/:change_id来定义。

import Xy from '@/components/xydm/index'{path:"/xy",component:Xy,name: 'xydm',children: [{path: '/xydm/rightForm/:change_id',name: 'xydmRightForm',component: xydmRightForm}]},

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。