美文网首页
vue父组件获取子组件的ref

vue父组件获取子组件的ref

作者: 有一个程序媛 | 来源:发表于2019-08-22 13:55 被阅读0次

父组件如何获取子组件的ref呢

父组件

<div>

<child></child>

</div>

子组件child

<div>

<el-table ref="person"></el-table>

</div>

如何获取子组件的table的clearSort() 方法呢?

方案:给父组件添加ref,一级一级往下找,找到子组件的ref,定位到为table,调用clearSort()

<div>

<child ref="people"></child>

</div>

this.$refs.people.refs.person.$children[0].clearSort()用于清空table的排序功能的蓝色箭头高亮

相关文章

    本文标题:vue父组件获取子组件的ref

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