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

How to implement route parameter passing in vue-router

亚连
亚连Original
2018-06-15 11:42:321795browse

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>

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>

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

3. Define the route , add a route

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

4. The entire code is as follows:




  
  
  
  

 
  

home news

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!

Statement:
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