自定义组件

自定义组件

组件样式
  • 样式隔离
options:{
stllelsolation:"isolated"//apply-shared父影响子 shared父子相互影响 isloated相互隔离
}
  • 外部类
externalClasses:["cell-class"]//定义

<view class="cell cell-class"></view >

页面中

<cell cell-class="mycell"></cell>
.nycell{
样式
}
组件的插槽
  • 默认插槽
    父组件 < cell > < text>插槽内容< /text> < /cell >
    子组件< view> < slot>< /slot>< /view>
  • 命名多插槽
    options:{multipleSlots:true}
    父组件 < cell > < text slot=“one”>插槽内容< /text> < text slot=“two”>插槽内容< /text>< /cell >
    子组件< view> < slot name=“one”>< /slot>< slot name=“two”>< /slot>< /view>
组件传参
  • 父传子 property
  • 子传参父 triggEvent

组件的使用

定义组件
  • (js,wxml,json,wxss)
  • 页面的xxx.json usingComponent注册
"usingComponent":{
"cell":组件路径
}
  • 使用组件 < cell>< /cell>
自定义组件 Component
  • 生命周期 lifeitems attach组件的挂载
  • data数据
  • methods 方法
  • properties 属性 只读
  • externalClasses 外部类
  • options 选项 multipleSlots:true 多个插槽 stylesolation:“isolateed” 组件样式格式

自定义组件生命周期

组件的生命周期 lifeitems
  • created 创建 此时还不能调用 setData
  • attached 挂载
  • detached 卸载
页面生命周期
  • show 显示
  • hide 后台运行
  • resize 尺寸 变化
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值