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: '/news/:id', component: NewsDetail },
4. The entire code is as follows:
home news
首页
登录 注册
新闻列表
新闻001 新闻002 登录界面
注册界面
新闻详细页面 {{$route.params.id}}
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!