一个不错的vue表单验证插件

时间:2022-02-02 23:08:44

  github文档 用着不错,官方的文档例子很简单

<body>

    <div id="app">
<validator name="validation1">
<form novalidate>
<div class="username-field">
<label for="username">username:</label>
<input id="username" type="text" v-validate:username="['required']">
</div>
<div class="comment-field">
<label for="comment">comment:</label>
<input id="comment" type="text" v-validate:comment="{ minlength: 2 }">
</div>
<div class="errors">
<p v-if="$validation1.username.required">Required your name.</p>
<p v-if="$validation1.comment.minlength">Your comment is too long.</p>
</div>
<input type="submit" value="send" v-if="$validation1.valid">
</form>
</validator> <script>
var vm = new Vue({
el: '#app'
})
</script>
</body>

  直接用就可以了,自己把CSS改一下,就能用在现在的项目上了。