vue.js - 在没有点击事件Vue js的情况下在子组件之间传递“ref”
问题描述
我有两个兄弟组件,一个有一个表单,提交按钮在下一个组件中。我想将 ValidateObserver(来自 vee-validate)作为参考传递给其他子组件。我使用全局 Eventhub 在兄弟组件之间进行通信。
// Component A
<template>
<ValidationObserver v-slot="{ handleSubmit }" ref="FullForm">
<form @submit.prevent="handleSubmit(buildingForm)">
</template>
methods:{
buildingForm(){
this.eventHub.$emit('building-form', data)
},
},
我在组件 B 上发现了它
//Component B
methods(){
buildingValidation(){
this.$refs.FullForm.validate().then(success => {
if (!success) {
return this.step.id == this.currentstep;
}
});
},
}
created(){
this.eventHub.$on('building-form', data => {
//Here I'm calling the function buildingValidation()
console.log(data);
})
},
我错过了什么?谢谢
解决方案
推荐阅读
- networking - Network Manager 服务在 RHEL7-8 中分配网络中已使用的 IP
- javascript - javascript动画onclick函数和javascript会话
- apache-spark - spark - 基于另一个布尔列的条件累积和
- json - 如何将 PIL 图像转换为 JSON 可序列化字符串,反之亦然?
- html - 尽管使用了 media=print,谷歌字体仍会阻止渲染
- android - Android,如何从同一个 ViewModel 中观察 LiveData
- mongodb - 当您知道键但不知道值时,访问 mongo 对象内的值
- react-native - 如何在 React-Native for Web 上更改 React-Native-Elements 库的 Tab 组件上的选项卡颜色?
- php - Laravel如何在虚拟主机上加载上传的图片
- json - 将json响应添加到flutter中的列表