{
"usingComponents": {
//"Tab" 是自己定义的组件名称
//"../../components/Tab/Tab" 是组件的路径
"Tab":"../../components/Tab/Tab"
}
}
<Tab tabs="{{tabs}}" data-index={{index}}></Tab>
properties
来获取父组件传递的数据,接着子组件把这个数据当成是data
中的数据使用即可Component({
///组件的属性列表
properties: {
tabs:{
type:Array, //要接收的数据类型
value:[] //默认值(可选)
}
}
})
<button size="mini" bind:tap="handleTap">+1</button>
methods: {
handleTap(){
//三个参数:方法名称,子组件要往父组件传递的参数
this.triggerEvent("increment",{index:0})
}
}
<Tab tabs="{{tabs}}" bindincrement="handleIncrement"></Tab>
handleIncrement(e){
//子组件向父组件传递过来的参数都储存在事件对象e中
const index = e.detail.index
this.setData({
count:this.data.count + index
})
}
原文:https://www.cnblogs.com/jincanyu/p/14349236.html