Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How does vue listen for routing

Shulou Source: shulou.com Published: 2022-05-31 13:25:04 09月24日 Update

This article introduces the knowledge of "how to monitor routing by vue". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The specific methods are as follows:

1. Use the watch method to listen for routes

Watch: {

$route (to,from) {

Console.log (from.path)

Console.log (to.path)

}

}

two。 Use the watch method to listen for routing changes and get routing information

Watch: {

$route: {

Handler (val,oldval) {

Console.log (val)

Console.log (oldval)

}

Deep: true

}

}

3. Use the beforeEach method to listen for routes globally

Router.beforeEach ((to, from, next) = > {

Console.log (to)

Next ()

});

Export default router

4. Use the beforeRoute method to listen for routes within a component

BeforeRouteEnter (to, from, next) {

}

BeforeRouteUpdate (to, from, next) {

}

BeforeRouteLeave (to, from, next) {

}

That's all for "how vue monitors routing". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Routing monitoring methods content more knowledge practicality learning next information overall situation dilemma reality situation articles cases components editing websites industry Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information OPPO Reno Apple Shulou Technology NVidia