Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
659 views
in Technique[技术] by (71.8m points)

vue中父组件调用子组件的方法都有哪些?他们在性能上有区别吗?或者建议通过什么方式去获取子组件的方法

最近在一个群里有个小伙伴说 在react中不建议通过ref的形式去获取子组件的一些方法,这种方式在性能上消耗较大,所以我就想在vue中通过这方式是否会有这样的顾虑?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

使用callback ref代替string ref

eg:

// string ref
<ComponentA ref="componentA"/>
// callback ref
<ComponentA ref="(com) => { this.componentA = com }"/>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...