zoukankan      html  css  js  c++  java
  • 直接引用vee-validate校验插件

    直接在页面引用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 /^1d{10}$/.test(value); } }); Vue.use(VeeValidate);
    var vue = new Vue({
    el: "#test",
    data: {
    submitDisabled: true,
    ruleForm: {
    …………代码省
  • 相关阅读:
    定时任务 常用cron表达式
    链接UTF-8编码带BOM尾,访问出现404
    centos安装nginx
    cnetos安装jdk
    javaweb数据分页
    mvn clean install对idea中项目结构的影响
    spring使用servlet过滤器filter,进行登录校验
    docker安装mysql并修改远程登陆权限
    使用token令牌控制接口幂等性
    718.最长重复子数组
  • 原文地址:https://www.cnblogs.com/SimonHu1993/p/9230704.html
Copyright © 2011-2022 走看看