问题描述:在当前页面使用$router.push带参数跳转当前页面时,页面会出现报错并页面没有刷新的情况
问题解决:
app.vue页面修改
<template>
<div id="app">
<router-view v-if="isRouterAlive"/>
</div>
</template><script>
export default {
name: 'App',
provide (){
return {
reload: this.reload
}
},
data(){
return {
isRouterAlive: true
}
},
methods:{
reload(){
this.isRouterAlive = false;
this.$nextTick(function(){
this.isRouterAlive = true;
})
}
}
}
</script><style>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
/* text-align: center; */
/* color: #2c3e50; */
/* margin-top: 60px; */
}
</style>
在需要进行跳转操作的页面
this.$router.replace({
name: "type",
query: {typeid: id}
},()=>{
that.reload();//刷新页面
})
这样就可以实现跳转当前页面并刷新页面的操作了