Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

vue3中如何实现触发点击事件时,改变子组件的值?

最近在学习vue3的知识,看到了provide和inject,想请教下如何能实现父组件中的一个按钮触发点击事件时,改变子组件的值?
我试着把provide写到了点击事件中,会出现下面的警告
image.png
那么怎么样才能实现呢?


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

1 Answer

0 votes
by (71.8m points)

如果是子组件的props,直接在父组件里面修改就可以了。
如果是组件的setup返回的值,还是用ref取得子组件的引用进行修改。

警告的意思是provide必须在setup函数中使用,你可以去看下vue3 composition API


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...