一、直接刷新当前页面的方法
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}]},