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

A simple understanding of ES6 iterators

 What is an iterator?An iterator is an interface that provides a unified access mechanism for various data structures. Any data structure can complete the traversal operation as long as the iterator interface is deployed.ES6 created a new traversal command for...of loop, which natively has a data structure with the iterator interface (which can be traversed with for...of). Contains Array, Arguments, Set, Map, String, TypedArray, NodeList. Of course, you can also implement this interface manually, which is convenient for practical use.