vue parent成分从子方法获取响应
我有父母组成部分和一个孩子。 从父母那里,我想调用儿童组件中的方法并等待响应。我该怎么做? 我需要响应以在父方法中添加条件。
<!-- MY CHILD COMPONENT -->
<my-child-component ref="childform" />
// parent method
methods: {
callChildMethod() {
this.$refs.childform.onSubmit()
// if want to get the response and do something
if (response) {
//do something
}
},
}
//child method
methods: {
onSubmit() {
//do something
return false
},
}
I have a parent component and a child.
From parent i want to call a method in child component and wait the response. How can i do that?
I need the response for adding a condition in the parent method.
<!-- MY CHILD COMPONENT -->
<my-child-component ref="childform" />
// parent method
methods: {
callChildMethod() {
this.$refs.childform.onSubmit()
// if want to get the response and do something
if (response) {
//do something
}
},
}
//child method
methods: {
onSubmit() {
//do something
return false
},
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题可以使用参考来解决,并且可以如下工作:
在父组件中:
在您的父脚本标签中:
Your problem could be solved using refs and it works as follows:
In parent component:
In your parent script tag: