【发布时间】:2019-09-02 23:09:25
【问题描述】:
在以下方法中,您认为哪种做法更好?
[1]使用$emit将子组件的方法暴露给父组件
$emit('updateAPI', exposeAPI({ childMethod: this.childMethod }))
或
[ 2 ] 使用父组件中的$refs 访问子组件方法
this.$refs.childComponent.childMethod()
【问题讨论】:
-
你应该在这里阅读答案。一切都解释得很好,便于理解。 stackoverflow.com/questions/40957008/…
-
发射 - 绝对。它完全解耦了父元素和子元素以增加可重用性。
标签: javascript vue.js vue-component