gpt4 book ai didi

vuejs2 - Vee-validate 总是返回 true

转载 作者:行者123 更新时间:2023-12-04 02:59:46 25 4
gpt4 key购买 nike

我有 2 个字段要验证,但在我提交后总是在方法 validateBeforeSubmit() 中返回 true。

Whitout 按钮提交它工作得很好,并以良好的语言返回 errors.first(name)

我做错了什么?

App.vue:

<form @submit.prevent="validateBeforeSubmit">

<form-input v-on:input="handleTitle" :validate="'required|email'" label="email" labelvalue="email" type="text" placeholder="" name="email" :value="title" classname="form-control" id=""></form-input>
<form-input v-on:input="handleLink" :validate="'required'" label="Link" labelvalue="Link" type="text" placeholder="" name="link" :value="link" classname="form-control" id=""></form-input>

methods: {
validateBeforeSubmit() {
this.$validator.validateAll().then((result) => {
if (result) {
// eslint-disable-next-line
alert('Form Submitted!');
return;
}

alert('Correct them errors!');
});
},

输入.vue:

<template>
<div>
<div class="form-group">
<span>{{ errors.first(name) }}</span>
<label v-if="label" :for="label" v-html="labelvalue"></label>
<input v-validate="validate" v-on:input="updateValue($event)" :type="type" :placeholder="placeholder" :name="name" :value="value" :class="classname" :id="id">
</div>
</div>
</template>

export default {
props: {
validate: String,
type: String,
placeholder: String,
name: String,
value: String,
classname: String,
id: String,
label: String,
labelvalue: String
},
methods: {
updateValue: function (evt) {
this.$emit('input', evt)
}
}
}

最佳答案

validateAll 不会查看子组件。您必须注入(inject)父验证器。在 Input.vue 文件中添加 inject: ['$validator']。它应该可以解决问题。导出 block 将如下所示

export default {
inject: ['$validator'],
props: {
validate: String,
type: String,
placeholder: String,
name: String,
value: String,
classname: String,
id: String,
label: String,
labelvalue: String
},
methods: {
updateValue: function (evt) {
this.$emit('input', evt)
}
}
}

有关inject 的更多信息,您可以查看this reference

关于vuejs2 - Vee-validate 总是返回 true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50231479/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com