Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Vue routing

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to use Vue routing". In daily operation, I believe many people have doubts about how to use Vue routing. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use Vue routing". Next, please follow the editor to study!

In Vue, the so-called routing is actually similar to the concept of routing in other frameworks, that is, the jump path.

Note: in Vue, to use routing, vue-router.js must be imported, and it needs to be imported under vue.js.

Specific examples are as follows:

View 1

View 2

/ / 1. Define routing components

Var T1 = {template: "hello, view1"}

Var T2 = {template: "hello, view2"}

/ / 2. Define routing rules

Var routes = [

{path: "/ view1", component: T1}

{path: "/ view2", component: T2}

]

/ / 3. Build a rout

Var router = new VueRouter ({routes:routes})

/ / 4. Bind routin

Var v = new Vue ({

Router: router

}). $mount ("# content")

The analysis is as follows:

In the page tag, you need the event link tag that the view triggers. Then you need a display view label for the toggle page.

In the js code, you first define the routing component, that is, the specific content that the page needs to display. Then define the rules, that is, which link triggers the display of which specific content. Once again, you need to build the rules defined above into a routing object in vue. Finally, bind the defined routing object to the current vue view.

If you need to pass parameters in the link, you can do the following:

View 1

Equivalent to / view1?name=leon

At this point, the study on "how to use Vue routing" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report