Vue query, params parameter passing

a jump b page parameter
1, query
(1) a.vue:

 this.$router.push({
    
     
 path: "/b", 
 query: {
    
    id:'home', name:'query'} });

(2) b.vue:

console.log(this.$route.query.id)

(3) Routing:

{
    
    
path: '/b',
name: 'b',
component: () => import('@/view/b')
}

2、params
(1) a.vue:

 this.$router.push({
    
     
 name:'b',  //这里注意path和name
 params: {
    
    id:'home', name:'params'} });

Note: path will ignore the params attribute

const userId = '123'
router.push({
    
     name: 'user', params: {
    
     userId }}) // -> /user/123
router.push({
    
     path: `/user/${
    
    userId}` }) // -> /user/123
// 这里的 params 不生效
router.push({
    
     path: '/user', params: {
    
     userId }}) // -> /user

(2) b.vue:

console.log(this.$route.params.id)

(3) Routing:

{
    
    
path: '/b/:id/:name',  //加参数的原因
name: 'b',
component: () => import('@/view/b')
}

Note: The reason for adding parameters is that
there are no parameters in the address bar, the page jump fails or the page has no content

Reference:
The use and difference of Vue Router's params and query parameters (detailed)

Guess you like

Origin blog.csdn.net/Ann_52547/article/details/130492052
Recommended