直接在页面引用vee-validate

源文件下载地址:http://www.bootcdn.cn/vee-validate/

官方api https://baianat.github.io/vee-validate/guide/rules.html#is-not

       .is-danger {
border: 1px solid red;
}
.is-danger>span{//默认none,防止初始化时显示{{error信息}}
display: block;
}

注:vee-validate支持对象表示方法,支持动态取消校验:

v-validate="{
required: !(brandBaseItem && brandBaseItem.logoName),//作为动态校验规则
image: true,
size: 300,
ext: ['png', 'jpeg', 'jpg', 'bmp']}"

https://segmentfault.com/q/1010000013117209

 <script th:src="@{/js/vee-validate/vee-validate.min.js}"></script>
<script th:src="@{/js/vee-validate/vee-zh_CN.js}"></script>
<input v-validate="'required|phone'" :class="{'input': true, 'is-danger': errors.has('phone') }" name="phone" type="text" placeholder="phone" />
<br/>
<span v-show="errors.has('phone')" style="display:none;color: red;font-size: 12px;">{{ errors.first('phone') }}</span> <br/> <input v-validate="'required|email'" :class="{'input': true, 'is-danger': errors.has('email') }" name="email" type="text" placeholder="email" /> <br/> <span v-show="errors.has('email')" style="color: red;font-size: 12px;">{{ errors.first('email') }}</span>
<script th:inline="javascript">
/*<![CDATA[*/
//引入vue后,需要添加vee-validata的js和语言包文件(目前只用中文)
 VeeValidate.Validator.localize('zh_CN');
//js使用方式,指定语言、修改默认提示,添加自定义验证
VeeValidate.Validator.localize({
zh_CN:{
messages:{
required:function (name) {
return name+"不能为空!";
},
email:function () {
return "邮箱格式无效"
},
},//定义成我们需要的文字提示
attributes:{
email:'邮箱',
phone: '手机',
},
}
 }); VeeValidate.Validator.extend('phone',{ getMessage:function () { return "请输入正确手机号!"; }, validate:function (value) { return /^1\d{10}$/.test(value); } }); Vue.use(VeeValidate);
var vue = new Vue({
el: "#test",
data: {
submitDisabled: true,
ruleForm: {
…………代码省

最新文章

  1. Parcelable序列化的使用,关于intent.getParcelableArrayExtra的使用
  2. s:if 判断
  3. c语言,检测一个无符号整数中是否有偶数位个1
  4. php常用的数组函数
  5. 关于PDF文件无法打印的问题的解决办法
  6. 卡特兰数 BZOJ3907 网格 NOIP2003 栈
  7. cocoapods 的使用心得
  8. MicrosoftSQLServer中的锁模式
  9. Spring MVC和Struts2的比较
  10. Android远程桌面助手之功能简介
  11. ArrayList循环遍历并删除元素的常见陷阱
  12. Linux shell if判断语句
  13. Scrapy 框架 中间件,信号,定制命令
  14. FreeMaker入门介绍
  15. Android Studio手动打包
  16. 由JDBC而来的对Class.forName()用法发散
  17. 我的Java之旅 第一课 开发环境准备
  18. c# 项目的导入
  19. python-切片实例
  20. Sencha Touch 实战开发培训 视频教程 第二期 第七节

热门文章

  1. 10分钟了解Android的Handler机制
  2. Confluence 6 导入一个 Confluence 站点
  3. ncnn编译安装
  4. pytorch:修改预训练模型
  5. Java并发编程基础-ReentrantLock的机制
  6. LeetCode(107): 二叉树的层次遍历 II
  7. TypeError: $(…).tooltip is not a function
  8. Distance
  9. python 全栈开发,Day71(模型层-单表操作)
  10. 论文阅读笔记十七:RefineNet: Multi-Path Refinement Networks for High-Resolution Semantic Segmentation(CVPR2017)