Vee-validate - [Vue 警告]:无法解析指令:验证
Vee-validate - [Vue warn]: Failed to resolve directive: validate
我想验证文本字段,尝试以下代码:
<input v-validate="result.val=='Required' ? 'required' : ''" v-model="required" :name="f_name" type="text"/>
但出现此错误:
app.js:48089 [Vue warn]: Failed to resolve directive: validate
试试这个:
<ValidationProvider name="phone" :rules="required" v-slot="{ errors }">
<input class="form-control" :name="phone" type="text" v-model="form.phone"/>
</ValidationProvider>
根据 migration guide,此指令已在 v3.x 中删除:
Fields that had the v-validate
directive needs to be wrapped by ValidationProvider
component now, and they need to use v-model to properly tag themselves for vee-validate.
So this:
<input type="text" name="field" v-validate="'required'">
<span>{{ errors.first('field') }}</span>
将 re-written 如下所示:
<ValidationProvider name="field" rules="required" v-slot="{ errors }">
<input type="text" v-model="value">
<span>{{ errors[0] }}</span>
</ValidationProvider>
您的代码应如下所示:
<ValidationProvider name="f_name" :rules="result.val=='Required' ? 'required' : ''" v-slot="{ errors }">
<input v-model="required" :name="f_name" type="text"/>
</ValidationProvider>
您应该将此添加到 main.js
:
import { ValidationProvider } from 'vee-validate';
Vue.component('ValidationProvider', ValidationProvider);
如果您没有使用捆绑器并在浏览器或 CDN 中使用 vee-validate:
<script>
// ...
Vue.component('validation-provider', VeeValidate.ValidationProvider);
// ...
</script>
我想验证文本字段,尝试以下代码:
<input v-validate="result.val=='Required' ? 'required' : ''" v-model="required" :name="f_name" type="text"/>
但出现此错误:
app.js:48089 [Vue warn]: Failed to resolve directive: validate
试试这个:
<ValidationProvider name="phone" :rules="required" v-slot="{ errors }">
<input class="form-control" :name="phone" type="text" v-model="form.phone"/>
</ValidationProvider>
根据 migration guide,此指令已在 v3.x 中删除:
Fields that had the
v-validate
directive needs to be wrapped byValidationProvider
component now, and they need to use v-model to properly tag themselves for vee-validate. So this:
<input type="text" name="field" v-validate="'required'">
<span>{{ errors.first('field') }}</span>
将 re-written 如下所示:
<ValidationProvider name="field" rules="required" v-slot="{ errors }">
<input type="text" v-model="value">
<span>{{ errors[0] }}</span>
</ValidationProvider>
您的代码应如下所示:
<ValidationProvider name="f_name" :rules="result.val=='Required' ? 'required' : ''" v-slot="{ errors }">
<input v-model="required" :name="f_name" type="text"/>
</ValidationProvider>
您应该将此添加到 main.js
:
import { ValidationProvider } from 'vee-validate';
Vue.component('ValidationProvider', ValidationProvider);
如果您没有使用捆绑器并在浏览器或 CDN 中使用 vee-validate:
<script>
// ...
Vue.component('validation-provider', VeeValidate.ValidationProvider);
// ...
</script>