一、父向子传值方式是通过属性的方式来传值
组件dialog3csService.js中:通过Component代替了Pages
Component({
/**
* 组件的属性列表
*/
properties: {
attrResult: {
type: Object,
value: {}
},
checkedSkuList:{
type:Array,
value:[]
},
},
。。。
父文件home.json中引入组件
"usingComponents": {
"dialog3csService":"/components/dialog3csService/dialog3csService"
}
父文件home.whml中引入组件的标签
<dialog3csService attrResult="{{attrResult}}" checkedSkuList="{{checkedSkuList}}" bind:selected3csService="reportData" bind:sendservicenum="sendservicenum" ></dialog3csService>
二、子向父传值第一种方法triggerEvent() 方法
triggerEvent方法用法类似于Vue中的emit()
// dialog3csService 组件 js
ready: function () {
//上报数据
let data = {
serviceNum: 2
}
this.triggerEvent("sendservicenum", data, {});
},
home.js 父组件
sendservicenum(e){
this.setData({
serviceNum: e.detail.serviceNum,
});
},