Use of Vue-cli Router

Source: Internet
Author: User

After using this Vue-cli for a long time, you can't even get started. To avoid forgetting it, it is necessary to remember it.

 

About the use of the router in Vue-CLI ,,

I store all the pages in the components folder,

Use index. js in the router folder to direct the route

Use app. vue to control the router by pointing

 

App. vue

==============

<Router-link: To = "{Name: 'about'}"> about </router-link>

<Router-link: To = "{Name: 'version'}"> version </router-link>

<Router-View/>

 

 

Router-> index. js

==============

Import home from '@/components/home'

Import about from '@/components/about'

Import version from '@/components/version'

 

Export default new router ({

Routes :[

{Path: '/user/: id', component: Home,

Children :[

{Path: 'about', name: 'about', component: about },

{Path: 'version', name: 'version', component: Version}

]

}

]

})

 

Components-> Home. vue

As a parent-level control, it must contain the router-view command; otherwise, it cannot be displayed,

==============

<Div>

I am home

<Router-View> </router-View>

</Div>

 

The display logic of Vue-CLI is:

======================================

App. vue [router-View]

L home. vue [router-View] -- parent node-displays child nodes through router-View

L about. vue -- children displays the child nodes on the parent node

L version. vue -- the Child Nodes Displayed by children are displayed by the parent node

Use of Vue-cli Router

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.