国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

vue Render中slots的使用的實例代碼

2019-11-19 16:02:20
字體:
來源:轉載
供稿:網友

本文介紹了vue Render中slots的使用的實例代碼,有需要了解vue Render中slots用法的朋友可參考。希望此文章對各位有所幫助。

render 中 slot 的一般默認使用方式如下:

this.$slots.default 對用 template的<slot>的使用沒有name 。

想使用多個slot 的話。需要對slot命名唯一。使用this.$slots.name 在render中添加多個slot。

<body>   <div class="" id="app">   <myslot>     <div>this is slot</div>   </myslot>     </div>   <script>   Vue.component('myslot',{     render:function(createElement){        var he=createElement('div',{domProps:{innerHTML:'this child div'}});       return createElement('div',[he,this.$slots.default])       }   });   var app=new Vue({     el:'#app'   })   </script>   </body>  

多個slot的使用

<body>   <div class="" id="app">   <myslot>     <div slot="name1">this is slot</div>     <div slot="name2">The position is slot2 </div>   </myslot>     </div>   <script>   Vue.component('myslot',{     render:function(createElement){        var he=createElement('div',{domProps:{innerHTML:'this child div'}});       return createElement('div',[he,this.$slots.name2,this.$slots.name1])       }   });   var app=new Vue({     el:'#app'   })   </script>   </body> 

在vue2.1.0新添加了scope(雖然感覺有點怪,但是用習慣了,還蠻好用的)。同樣給出一般使用和多個使用示例,

<body>   <div class="" id="app">   <myslot>     <template scope="props">       <div>{{props.text}}</div>     </template>    </myslot>     </div>   <script>   Vue.component('myslot',{     render:function(createElement){        var he=createElement('div',{domProps:{innerHTML:'this child div'}});       return createElement('div',[he,this.$scopedSlots.default({         text:'hello scope'       })])       }   });   var app=new Vue({     el:'#app'   })   </script>   </body> 

多個$scopedSlot的使用

<body>   <div class="" id="app">   <myslot>     <template slot="name2" scope="props">       <div>{{props.text}}</div>     </template>     <template slot="name1" scope="props">       <span>{{props.text}}</span>     </template>    </myslot>     </div>   <script>   Vue.component('myslot',{     render:function(createElement){        var he=createElement('div',{domProps:{innerHTML:'this child div'}});       return createElement('div',         [he,         this.$scopedSlots.name1({         text:'hello scope'       }),         this.$scopedSlots.name2({         text:'$scopedSlots using'       })])       }   });   var app=new Vue({     el:'#app'   })   </script>   </body> 

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 原平市| 轮台县| 来凤县| 长治县| 越西县| 吐鲁番市| 武威市| 凤城市| 梅州市| 彩票| 榕江县| 禹城市| 普宁市| 汪清县| 迁西县| 朝阳县| 香港| 江华| 临夏县| 老河口市| 突泉县| 澄江县| 滨海县| 犍为县| 北辰区| 平湖市| 瑞金市| 衡山县| 盐源县| 宝兴县| 鱼台县| 城市| 阳原县| 澎湖县| 车险| 封丘县| 罗田县| 台北市| 乌审旗| 宽甸| 仁化县|