1.router-link路由导航
例如:<router-link to="/a/123">routerlink传参</router-link>
2.调用$router.push实现路由传参
<button @click="deliverParams(123)">push传参</button>
methods: {
deliverParams (id) {
this.$router.push({
path: `/d/${id}`
})
}
}
mounted () {
this.id = this.$route.params.id
}
3.name匹配路由(参数不会暴露在地址栏)
<button @click="deliverByName()">params传参</button>
deliverByName () {
this.$router.push({
name: 'B',
params: {
sometext: '一只羊出没'
}
})
}
mounted () {
this.id = this.$route.params.id
}
4.query传递参数(参数会暴露在地址栏)
<button @click="deliverQuery()">query传参</button>
deliverQuery () {
this.$router.push({
path: '/c',
query: {
sometext: '这是小羊同学'
}
})
}
mounted () {
this.id = this.$route.query.id
}