小程序在父组件调用子组件的方法

当父组件引用了子组件的时候,会遇到父组件执行子组件的方法

父组件中的内容

wxml: 

<view wx:for="{{imgs}}" wx:key="index" style="width: 500rpx;height: 300rpx;margin: 30rpx auto;">
  <button bindtap="ondelete" style="" data-index="{{index}}">删除</button>
  <image src="{{item.url}}" style="width: 100%;height: 100%;"></image>
</view>

<xly-upload id='btn' customeStyle="true"  bindsuccess="uploadChange"binddelete="deleteChange" bindfail="uploadfail">
<text>上传</text>
</xly-upload>

js:   

ondelete(e) {
this.selectComponent('#btn').DelImg(e);
},

在父组件中调用子组件的删除方法DelImg,e为方法需要的参数

posted @ 2020-03-27 13:49  太极面  阅读(3370)  评论(0编辑  收藏  举报