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

首頁 > 語言 > JavaScript > 正文

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

2024-05-06 15:14:11
字體:
來源:轉載
供稿:網友

本文介紹了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>             
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 民勤县| 沂南县| 资阳市| 舒兰市| 千阳县| 房产| 江山市| 饶平县| 渑池县| 榆中县| 博客| 壤塘县| 惠来县| 江津市| 河津市| 肇州县| 彭山县| 康平县| 武夷山市| 天峻县| 威信县| 克山县| 沙坪坝区| 汾西县| 应用必备| 炎陵县| 泽库县| 赣州市| 井研县| 孝义市| 海伦市| 新干县| 太仓市| 宜兴市| 陆良县| 辽源市| 台南市| 迭部县| 衢州市| 兴山县| 蛟河市|