gpt4 book ai didi

javascript - Vee-validate 基本示例不起作用 - 错误未定义

转载 作者:行者123 更新时间:2023-12-01 00:26:04 27 4
gpt4 key购买 nike

我正在尝试使用 vee-validate 制作一个简单的表单验证页面。但似乎有些东西被破坏了,我不确定我到底做错了什么。

我如何收到错误:错误未定义

<!DOCTYPE html>
<html>
<head>
<head>
<body>
<div id="app">
<h1>asdfasd</h1>
<form action='#' method='POST'>
<input v-validate="'required|email'" :class="{'input': true, 'is-danger': errors.has('email_primary') }" name="email_primary" type="text" placeholder="email_primary">
<span v-show="errors.has('email_primary')" class="help is-danger">{{ errors.first('email_primary') }}</span>
<button class="button is-link" name='submitform' value='go'>Submit</button>
</form>
</div>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/vee-validate/3.0.5/vee-validate.full.min.js"></script>
<script>
Vue.use(VeeValidate);
new Vue({
el: "#app",
template: '#app',
data() {
return {
email_primary: null
};
}
});
</script>
</body>
</html>

最佳答案

您似乎使用 veevalidate 3 而不是 veeValidate 2。我已在答案中将 veevalidate 更新为版本 2,并添加 v-model="email_primary"

由于您已有模板,因此我删除了 template: '#app',。请看下面

<!DOCTYPE html>
<html>

<head>

<head>

<body>
<div id="app">
<h1>asdfasd</h1>
<form action='#' method='POST'>
<input v-model="email_primary" v-validate="'required|email'"
:class="{'input': true, 'is-danger': errors.has('email_primary') }"
name="email_primary" type="text" placeholder="email_primary">
<span v-show="errors.has('email_primary')" class="help is-danger">{{ errors.first('email_primary') }}</span>
<button class="button is-link" name='submitform' value='go'>Submit</button>
</form>
</div>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.min.js"></script>
<script type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/vee-validate/2.2.15/vee-validate.min.js"></script>
<script>
Vue.use(VeeValidate);
new Vue({
el: "#app",
data() {
return {
email_primary: null
};
}
});
</script>
</body>
</html>

这是一个working fiddle 。希望我的回答对您有所帮助。

关于javascript - Vee-validate 基本示例不起作用 - 错误未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58989781/

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