1. router添加name, path后加/:参数
const routes = [
{
name: 'helloworld',
path: '/helloworld/:msg1',
component: HelloWorld
},
{
name: 'hellouniverse',
path: '/hellouniverse/:msg2',
component: HelloUniverse
}
]
2. router-link传递参数
<template>
<div>
<router-link :to="{name:'helloworld', params:{msg1:123}}">Hello World</router-link> |
<router-link :to="{name:'hellouniverse', params:{msg2:456}}">Hello Universe</router-link>
</div>
</template>
3. $route.params.xxx获取参数
<template>
<div>
<h1>Hello World</h1>
<h2>{{$route.params.msg1}}</h2>
</div>
</template>