99网
您的当前位置:首页vue3+vite3(四)router路由query和params的区别

vue3+vite3(四)router路由query和params的区别

来源:99网

都可以实现参数传递

1. query

配置:

//router.js
{
    path:'/about',
    name:'About',
    component:about
}

//home.vue
<router-link :to="{path:'about',query:{id:'1'}}"></router-link>

//about.vue
import {useRoute} form 'vue-router'

const route =useRoute()
console.log(route.query)

2. params

配置:

//router.js
{
    path:'/about/:id',
    name:'About',
    component:about
}

//home.vue
<router-link :to="{name:'about',params:{id:'1'}}"></router-link>

//about.vue
import {useRoute} form 'vue-router'

const route =useRoute()
console.log(route.params)

因篇幅问题不能全部显示,请点此查看更多更全内容