undefinedfix
Sign in

How to refresh the Vue router manually when entering the page

rpceo edited in Wed, 15 Jun 2022

I use this$ router.push () jump to a page, but I didn't get my data. I got it by refreshing it manually once. I think I will refresh it manually when I just enter this page. How can I do that?

3 Replies
notous
commented on Wed, 15 Jun 2022
this.$router.replace({
    path: '/refresh',
    query: {
      t: Date.now()
    }
  })
user618075
commented on Wed, 15 Jun 2022

The direction to solve the problem is not right, I suggest you break debugging. 1. Getting the data certainly doesn't need an extra refresh. 2. See if the method to get the data is called in the Vue life cycle.

nupanick
commented on Wed, 15 Jun 2022

The way to solve the problem is not right. Data acquisition can be executed in created, route.push If you don't execute the route under watch, you can get the data again.

created(){
    //created的时候执行获取数据的方法
    this.getData()
},
methods: {
    getData(){
        //你的的ajax获取数据
    }
},
watch: {
    //route.push进来后没有执行获取数据的方法可以watch下路由,有变化后再次获取数据,而不是靠刷新一次来获取数据
    $route(){
        this.getData()
    }
}
lock This question has been locked and the reply function has been disabled.