美文网首页
可以在主件里面调用子件的方法

可以在主件里面调用子件的方法

作者: 22222912 | 来源:发表于2020-11-26 19:30 被阅读0次

需求:componentLabelCopy 是一个子件  在页面(主件)引用,componentLabelCopy 里面有一个按钮,点击弹出dialog(但是dialog在ios端显示错误,所以就通过传值,让主件这边显示dialog,拿到输入的文字,再丢回给子件,去调用子件写好的方法去调用接口)

,在主件引用子键

利用 ref属性  componentLabel是这个子件的标识!

<componentLabelCopy ref="componentLabel" :dwRoleId="dwDetails.roleid" :dwId="dwId" typeId='0' :defaultStyle="false" :parentInputString="tempParentText" @saveLabel="clickLabel" @parentShowDialog="showParentDialog"></componentLabelCopy>

addUserTag(tempParentText)是componentLabelCopy 里面的方法

<van-dialog v-model="showParentAddTag" show-cancel-button @confirm="$refs.componentLabel.addUserTag(tempParentText)" @cancel="tempParentText=''">

      <div style="width: 100%;height:45px;line-height: 45px;text-align: center;">新增标签</div>

      <van-field v-if="showParentAddTag" class="onepxitem" v-model="tempParentText" autofocus maxlength="4" placeholder="请输入新标签(最多4个字符)"/>

    </van-dialog>

相关文章

网友评论

      本文标题:可以在主件里面调用子件的方法

      本文链接:https://www.haomeiwen.com/subject/layziktx.html