vue Render中slots的使用的實(shí)例代碼
本文介紹了vue Render中slots的使用的實(shí)例代碼,有需要了解vue Render中slots用法的朋友可參考。希望此文章對(duì)各位有所幫助。
render 中 slot 的一般默認(rèn)使用方式如下:
this.$slots.default 對(duì)用 template的<slot>的使用沒(méi)有name 。
想使用多個(gè)slot 的話。需要對(duì)slot命名唯一。使用this.$slots.name 在render中添加多個(gè)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>
多個(gè)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(雖然感覺(jué)有點(diǎn)怪,但是用習(xí)慣了,還蠻好用的)。同樣給出一般使用和多個(gè)使用示例,
<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>
多個(gè)$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>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
mpvue性能優(yōu)化實(shí)戰(zhàn)技巧(小結(jié))
這篇文章主要介紹了mpvue性能優(yōu)化實(shí)戰(zhàn)技巧(小結(jié)),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04jenkins自動(dòng)構(gòu)建發(fā)布vue項(xiàng)目的方法步驟
這篇文章主要介紹了jenkins自動(dòng)構(gòu)建發(fā)布vue項(xiàng)目的方法步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-01-01利用Vue.js框架實(shí)現(xiàn)火車(chē)票查詢(xún)系統(tǒng)(附源碼)
這篇文章主要介紹了利用Vue.js框架實(shí)現(xiàn)火車(chē)票查詢(xún)系統(tǒng)的相關(guān)資料,,文中給出了詳細(xì)的介紹與示例代碼,并在文章結(jié)尾給出了完整的項(xiàng)目下載,需要的朋友可以參考借鑒,下面來(lái)一起看看吧。2017-02-02vue實(shí)現(xiàn)兩個(gè)組件之間數(shù)據(jù)共享和修改操作
這篇文章主要介紹了vue實(shí)現(xiàn)兩個(gè)組件之間數(shù)據(jù)共享和修改操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-11-11vue.config.js配置報(bào)錯(cuò)解決辦法(可能是與webpack混淆)
在Vue.js開(kāi)發(fā)過(guò)程中,vue.config.js文件是用于配置項(xiàng)目的,特別是對(duì)于開(kāi)發(fā)環(huán)境的設(shè)置,這篇文章主要給大家介紹了關(guān)于vue.config.js配置報(bào)錯(cuò)解決的相關(guān)資料,可能是與webpack混淆,需要的朋友可以參考下2024-06-06vue中使用百度腦圖kityminder-core二次開(kāi)發(fā)的實(shí)現(xiàn)
這篇文章主要介紹了vue中使用百度腦圖kityminder-core二次開(kāi)發(fā)的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09