Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve the problem that vuejs route push does not jump

Shulou Source: shulou.com Published: 2022-06-02 20:01:47 09月16日 Update

Xiaobian to share with you how to solve the vuejs route push does not jump the problem, I hope you have something to gain after reading this article, let's discuss it together!

vuejs route push does not jump to the solution: 1, open vue-router jump code part of the content;2, add "watch: {'$route' (to, from) {...}, "Method;3. Monitor router changes and refresh the page.

Operating environment: Windows 7 system, vue2.9.6 version, DELL G3 computer.

How to solve the problem of vuejs route push not jumping?

vue-router with routing $router.push not jump A simple solution

Vue-router jump is usually written like this:

toCurrentPage: function(thisId){ this.$ router.push({path:'/test ', query: { id: thisId, option: ""}}); }

However, when you encounter a situation where you need to jump to a different query on the same page, the above method does not work. Of course, from a performance point of view, the theoretically best solution for this situation is to wrap the refresh into an init function, jump to the method, and pass the parameter to call the init method again. Balabalabala... not to repeat.

But in other cases, all components of the basic page need to be refreshed. Loading again has little impact on the overhead. You need history.back to ensure smooth operation logic... We only need to jump to load this, so it is actually very simple. Just add:

watch: { '$route' (to, from) { this.$ router.go(0); }},

Monitor router changes, refresh page ~

After reading this article, I believe you have a certain understanding of "how to solve the problem of vuejs route push not jumping". If you want to know more about it, welcome to pay attention to the industry information channel. Thank you for reading!

Tags: Methods pages problems situations again solutions articles solutions changes monitoring differences smoothness that's all small code functions content methods packages just Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi vpn Huawei Shulou Tech Info Microsoft