Skip to main content

Vue routing router props configuration.

 The role of props configuration in routing is to make it easier for routing components to receive parameters.It is very convenient to use. The following describes three ways to use props to pass and receive parameters.

Pass arguments of object type

{   name:"ddd",
                        path:"ddd/:id/:name",
                        component:DDD,
                        props:{a:100,b:"hello!!!"}
                    }
//
export default {
  name: 'DDD',
  props:["a","b"],

props is set to true, only parameters of type params will be passed

{   name:"ddd",
                        path:"ddd/:id/:name",
                        component:DDD,
                        props:true
                    }
//
  <router-link class="list-a"
            :to="{
                name:'ddd',
                params:{
                    id:item.id,
                    name:item.name
                }
            }"
            >{{item.title}}</router-link>
//
<ul>
     <li>{{$route.params.id}}</li>
    <li>{{$route.params.name}}</li>
  </ul>

How to write props function

{   name:"ddd",
                        path:"ddd/:id/:name",
                        component:Detail,
                        props(router){
                            return{
                            id:router.id,
                            title:router.name,
                            a:200,
                            b:"hello!!!"
                            }
                        }
                    }
//
<router-link class="list-a"
            :to="{
                name:'ddd',
                params:{
                    id:item.id,
                    name:item.name
                }
            }"
            >{{item.title}}</router-link>
//
<ul>
     <li>{{$route.params.id}}</li>
    <li>{{$route.params.name}}</li>
    <li>{{a}}=={{b}}</li>
  </ul>



Comments

Popular posts from this blog

Destructuring assignment in ES6

 In the past, when we wanted to assign a value to a variable, such as an array type and an object type, to assign a value to a variable, we could only specify the value directly. It is very troublesome to write in this way, but under the ES6 syntax specification, it is allowed to directly extract the required values from arrays and objects according to a certain pattern, and directly assign variables to variables. This method is called Destructuring, which is simple to understand. That is, the left and right sides of the equal sign are equal.

favicon.ico 404 Not Found Causes and Solutions

 What is favicon? It is the abbreviation of Favorites Icon. Its function is that in addition to displaying the corresponding title in the browser's favorites, icons can also be used to distinguish different websites. When I encounter this kind of error, I feel very uncomfortable. There is obviously no problem. Why is a 404 error reported? The following is the solution.