1、params传参(地址栏后url/参数)
路由表注册
const routes = {
path: '/user/:id',
name: 'user',
componente: User
}
// 传参直接加路径后面
this.$router.push('user/123212')
// 对象传参
this.$router.push({path: '/user', params: {id: '123456'})
vue2中接收
// 接收参数
this.$route.params.id
vue3接收
<script setup>
import {useRoute} from 'vue-router'
// vue3中useRoute()相当于this.$route
console.log(useRoute().params.id)
</script>
2、query方式传参(url?参数)
// vue2中对象传参
this.$router.push({path: '/about', query: {id: '123456'})