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

首頁(yè) > 編程 > JavaScript > 正文

微信小程序 slot踩坑的解決

2019-11-19 11:54:41
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

今天在使用微信小程序 component 里的 slot 時(shí)發(fā)現(xiàn),當(dāng)只用一個(gè) slot 并且將 slot 命名后,頁(yè)面中調(diào)用這個(gè) slot 并不會(huì)加載進(jìn)來(lái)。

研究嘗試后發(fā)現(xiàn),如果想要使用命名的方式調(diào)用單個(gè) slot ,也需要像調(diào)用多個(gè) slot 的方式 在 component/xxx.js 里開(kāi)啟多個(gè) slot 的功能。下面看代碼。

// component<view class='slot'> <view>哈哈哈哈哈哈哈哈</view> <slot name="after"></slot></view>// index 頁(yè)面<d-slot>  <!-- 這部分內(nèi)容將被放置在組件 <slot name="after"> 的位置上 -->  <view slot="after">這里是插入到組件slot name="after"中的內(nèi)容</view></d-slot>//結(jié)果,此時(shí)界面上不會(huì)載入 slot

而當(dāng)我把 slot 的name 刪去時(shí),slot 就能成功載入

// component<view class='slot'> <view>哈哈哈哈哈哈哈哈</view> <slot></slot></view>// index 頁(yè)面<d-slot>  <!-- 這部分內(nèi)容將被放置在組件 <slot name="after"> 的位置上 -->  <view>這里是插入到組件slot name="after"中的內(nèi)容</view></d-slot>//結(jié)果,此時(shí)界面上載入 slot

或者不刪去 name 而是在組件js中聲明啟用

// component.jsComponent({ options: { multipleSlots: true // 在組件定義時(shí)的選項(xiàng)中啟用多slot支持 }, properties: { /* ... */ }, methods: { /* ... */ }})// component<view class='slot'> <view>哈哈哈哈哈哈哈哈</view> <slot name="after"></slot></view>// index 頁(yè)面<d-slot>  <!-- 這部分內(nèi)容將被放置在組件 <slot name="after"> 的位置上 -->  <view slot="after">這里是插入到組件slot name="after"中的內(nèi)容</view></d-slot>//結(jié)果,此時(shí)界面上載入 slot

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 南通市| 大埔县| 古丈县| 平湖市| 灵寿县| 阿勒泰市| 博白县| 收藏| 张家界市| 长丰县| 新平| 吉首市| 赤峰市| 本溪市| 南部县| 嘉义县| 阳城县| 公主岭市| 当阳市| 贵溪市| 积石山| 安庆市| 芷江| 英山县| 苗栗县| 郎溪县| 峡江县| 迭部县| 邵东县| 鸡泽县| 镇江市| 茶陵县| 丹巴县| 平安县| 云梦县| 溆浦县| 柳林县| 和龙市| 昭苏县| 五寨县| 富阳市|