微信小程序-父子组件通信

父子组件通信

全局组件和局部组件的区别
父传子 properties
子传父 triggerEvent

插槽

子组件js文件内,配置支持插槽

Component({
  options: {
    multipleSlots: true // 在组件定义时的选项中启用多slot支持
  }
})

在组件内的wxml文件内,写入插槽

// first.wxml
<slot name="head"></slot>
view  
<slot name="foot"></slot>

在父组件内的子组件标签内调用

// index.html
<first>
   <view slot="head">123</view>
   <view slot="foot">123</view>
</first>
posted @ 2021-05-24 11:22  有风吹过的地方丨  阅读(105)  评论(0编辑  收藏  举报