vue 跳转当前页面改变url携带的参数并刷新页面

问题描述:在当前页面使用$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();//刷新页面
      })

 这样就可以实现跳转当前页面并刷新页面的操作了

扫描二维码关注公众号,回复: 14749272 查看本文章

猜你喜欢

转载自blog.csdn.net/lovewangyage/article/details/129109840