需求:点击同一个路由,重复刷新页面
解决思路:
1.放一个刷新页面 ,此页面为空页面,如下:
<template>
</template>
<script>
export default {
beforeRouteEnter(to,from,next){
next((vm) => {
vm.$router.replace(from.path);
});
}
}
</script>
<style>
</style>
2。配置下路由规则
{
path: "/refresh",
name: "refresh",
hideInMenu: true,
component: () =>
import( "@/components/refresh"),
},
3.点击当前路由时候,跳转刷新页,再从刷新页回调,即可完成刷新
if(this.$route.path === path) {
this.$router.replace({ path: '/refresh' });
return
}
本文介绍了如何使用Vue.js通过设置路由守卫,实现点击某个路由时自动跳转到一个空页面并刷新,随后通过回调返回,从而实现页面的重复刷新。步骤包括创建一个隐藏路由、配置路由规则和判断路径进行跳转。
4322

被折叠的 条评论
为什么被折叠?



