How to pass a method in Vue.js slot scope

后端 未结 3 2381
灰色年华
灰色年华 2021-02-20 16:38

I\'m using a slot scope in vuejs. It\'s working great. I can pass anything I want into the slot like this:

    

         


        
3条回答
  •  情书的邮戳
    2021-02-20 17:12

    UPDATE

    This answer was written for the older pre v2.6 syntax. Since then, this syntax has been marked for deprecation. The core functionality stays the same, the functions(methods) work the same way as the properties that are being bound upwards (from child to parent), however the definition uses v-slot:default now.

    as per updated documentation (https://vuejs.org/v2/guide/components-slots.html#Scoped-Slots),

    
      
        {{ user.lastName }}
      
    
    

    Attributes bound to a element are called slot props. Now, in the parent scope, we can use v-slot with a value to define a name for the slot props we’ve been provided:

    
      
    
    

    Here is a more complicated example, as you will notice, the function and the scoped slots are passed using slotProps


    Original answer with pre v2.6 syntax. Example of how to pass the slot-scope

    parent:

    
    

    child:

    
    
    
    

提交回复
热议问题