【发布时间】:2019-05-06 19:05:03
【问题描述】:
我是 Vue Js 和 Vuelidate 的新手。刚刚尝试验证来自父组件的表单输入字段,如下所示:https://github.com/monterail/vuelidate/issues/333
父组件中的子组件:
<contact-list ref="contactList" :contacts="contacts" @primaryChanged="setPrimary" @remove="removeContact" @ready="isReady => readyToSubmit = isReady"/>
子中的方法:
computed: {
ready() {
return !this.$v.email.$invalid;
}
},
watch: {
ready(val) {
this.$emit('ready', val);
}
},
methods: {
touch() {
this.$v.email.$touch();
}
}
我像这样从父级调用 touch() 方法:
submit() {
this.$refs.contactList.touch();
},
但我得到这个错误:
Error in event handler for "click": "TypeError: this.$refs.contactList.touch is not a function".
有什么想法吗?谢谢。
【问题讨论】:
-
似乎没问题。您是否尝试在创建
contact-list之前调用它?
标签: vue.js vuejs2 vue-component vuelidate