vue--dynamic Routing and get transfer values

Source: Internet
Author: User

Dynamic routing:

<Template>  <DivID= "News">    <V-header></V-header>    <HR>{{title}}<BR>    <Pv-for= "(x,k) in list">      <!--<router-link to= "/content/123" >{{k}}-{{x}}</router-link> -      <!--because we want to bind our dynamic data, we use: And then we do the stitching . -      <Router-link: to= "'/content/' +k">{{k}}-{{x}}</Router-link>    </P>  </Div></Template><Script>Import Header from'./header.vue'; exportdefault{name:'News', data () {return{title:'I'm a news component .', list:['111','222','3330','444']}}, methods:{}, components:{'V-header': Header,}}</Script>

Click to jump to a detail: You can create a new detail component:

<Template>    <DivID= "Content">{{title}}----{{aid}}</Div></Template><Script>Exportdefault{name:'Header', data () {return{title:'I am a detail page', aid:"',}}, methods:{run () {},}, mounted () {//gets the value of the dynamic route passed overConsole.log ( This. $route. Params); Console.log ( This. $route. params['Aid']);  This. Aid=  This. $route. params['Aid']; }}</Script></Script>

You also need to configure routing at this time:

// 1. Create the component import Header from './components/header.vue'./components/home.vue './components /news.vue './components/content.vue '//  2, configure the route const routes = [  '/home ', Component:home},  '/news ', Component:news  }, '/content ', component:content},  /c13> '/content/:aid ', component:content},  //  default jump route ]

Get Pass Value:

<p vfor = "(x,k) in list" >  <!--<router-link to= "/content?aid=123" >{{k}}-{{x}}</ Router-link>--  <router-link:to= "'/content?aid= ' +k" >{{k}}-{{x}}</router-link></p>

To configure routing:

// 2. Configure the route const routes =  ['/home ', Component:home  },'/news ', Component:news},< c10/>'/content ', component:content},  //  default jump route ]

Get Parameters:

mounted () {    // Gets the value Console.log (this. $route. Query)         for the dynamic route passed over by get. Console.log (this. $route. query[' aid ');      This this. $route. query[' aid '];}

vue--dynamic Routing and get transfer values

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.