Home > Web Front-end > JS Tutorial > How to implement route parameter passing in vue-router

How to implement route parameter passing in vue-router

亚连
Release: 2018-06-15 11:42:32
Original
1763 people have browsed it

This article mainly introduces the method of passing parameters in vue-router routing. Now I will share it with you and give you a reference.

Routing parameters. Many times we need to pass parameters on the route, such as the news list page, we need to pass the news ID to the news details page.

1. News list page template

 <template id="news">
    <p>
      <h2>新闻列表</h2>
      <ul>
        <li>
          <router-link to="/news/001">新闻001</router-link>
        </li>
        <li>
          <router-link to="/news/002">新闻002</router-link>
        </li>
      </ul>      
    </p>
  </template>
Copy after login

We visit /news/001, jump to the news details page, and display the news of 001.

2. News detail page component preparation

 <template id="NewsDetail">
    <p>
      新闻详细页面
      <span>{{$route.params.id}}</span>
    </p>
  </template>
Copy after login

$route.params.id gets the parameters on the route

3. Define the route , add a route

{ path: &#39;/news/:id&#39;, component: NewsDetail },
Copy after login

4. The entire code is as follows:




  
  
  
  

home news

Copy after login

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

How to connect the printer in javaScript

How to pass events in the vue component

Detailed introduction to the use of Vue event modifier capture

404 problem occurs when refreshing the page in react-router

The above is the detailed content of How to implement route parameter passing in vue-router. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template