子传父
子
html
<view bindtap="send">子向父传参</view>
js
send(){
this.triggerEvent("send",'world')
}
父
html
<y-tab bindsend="getChildData"></y-tab>
<view>{{childMsg}}</view>
js
getChildData(e){
this.setData({
childMsg: e.detail
})
}
父传子
父
html
<y-tab class-id="{{cur}}"></y-tab>
js
data:{
cur:5,
}
子
js
properties: {
classId: {
type: Number,
// 默认值
value: 100
}
},
// 在组件定义时的选项中启用多slot支持
options: {
multipleSlots: true
},
methods:{
getData() {
//模拟网络请求
let list = tabList.filter(item => {
return item.classId == this.data.classId
})
this.setData({
list: list[0].contList
})
},
}