1、问题
在vue的项目使用vue-router时,可能会遇到跳转本页面刷新当前页面的需求。如果直接使用vue-router的方法来跳转,页面是不会刷新的。
2、解决办法
解决办法如下面的代码所示:
<template> <div class="app"> <router-view v-if="isRouterActive"></router-view> </div> </template> <script> export default { name: ‘app‘, data(){ return { isRouterActive: true } }, methods: { reload(){ this.isRouterActive = false; this.$nextTick(function(){ this.isRouterActive = true; }) } } } </script>
在上述代码中我们声明了一个isRouterActive的变量,它控制着router-view路由入口的显示。当我们想刷新页面时,就可以调用reload函数来完成当前页面的刷新。
原文:https://www.cnblogs.com/tidemode/p/12773102.html