vue3跳转时传参
两种传参方式
分别是query和params
- query
传入方
import { useRouter } from "vue-router";
const router = useRouter()
const go = () => {
router.push({
path: '/login',query:{name:'天赐'}
})
}
接收方
import { useRoute } from "vue-router";
const route=useRoute()
console.log(route.query.name);
- params需要搭配动态路由
路由
{
path: '/login/:id',
name: 'Login',
component: () => import('../views/login.vue')
}
传入方
import { useRouter } from "vue-router";
const router = useRouter()
const go = () => {)
router.push({
name: 'Login',
params: {
id: 1
}
})
}
接收方
import { useRoute } from "vue-router";
const route=useRoute()
console.log(route.params.id);