Vue中表单校验

1.安装校验插件vee-validate

npm install vee-validate --save

 2.在main.js中引用插件

// 表单校验
import VeeValidate, { Validator } from 'vee-validate';
import zh_CN from 'vee-validate/dist/locale/zh_CN'

Vue.use(VeeValidate)
Validator.localize('zh_CN', zh_CN);

 3.基础使用

<div class="loginline">
	<input type="text" placeholder="账号" v-model="username" name="username" v-validate="'required|min:2'" data-vv-as="账号" >
	<span class="errormsg">{{ errors.first('username') }}</span>
</div>

 

posted @ 2019-01-23 16:15  lilyliu329  阅读(711)  评论(0编辑  收藏  举报