国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

詳解vue表單驗(yàn)證組件 v-verify-plugin

2019-11-19 16:47:51
字體:
供稿:網(wǎng)友

verify

github:https://github.com/liuyinglong/verify

npm:https://www.npmjs.com/package/vue-verify-plugin

install

npm install vue-verify-plugin

use

html

<div>  <div>    <input type="text" placeholder="姓名" v-verify.grow1="username" v-model="username"/>    <label v-verified="verifyError.username"></label>  </div>  <div>    <input type="password" placeholder="密碼" v-verify.grow1="pwd" v-model="pwd"/>    <label v-verified="verifyError.pwd"></label>  </div>  <button v-on:click="submit">確認(rèn)</button> </div>

js

import Vue from "vue";import verify from "vue-verify-plugin";Vue.use(verify);export default{  data:function(){    return {      username:"",      pwd:""    }  },  methods:{    submit:function(){      if(this.$verify.check()){        //通過驗(yàn)證        }    }  },  verify:{    username:[      "required",      {        test:function(val){          if(val.length<2){            return false;          }          return true;        },        message:"姓名不得小于2位"      }    ],    pwd:"required"  },  computed:{    verifyError:function(){      return this.$verify.$errors;    }  }}

指令說明

v-verify

v-erify 在表單控件元素上創(chuàng)建數(shù)據(jù)的驗(yàn)證規(guī)則,他會自動匹配要驗(yàn)證的值以及驗(yàn)證的規(guī)則。

v-verify 修飾符說明

該指令最后一個修飾符為自定義分組

//自定義teacher分組v-verify.teacher//自定義student分組v-verify.student//驗(yàn)證時可分開進(jìn)行驗(yàn)證 //驗(yàn)證student 分組this.$verify.check("student")//驗(yàn)證teacher 分組this.$verify.check("teacher")//驗(yàn)證所有this.$verify.check();

v-verified

v-verified 錯誤展示,當(dāng)有錯誤時會展示,沒有錯誤時會加上style:none,默認(rèn)會展示該數(shù)據(jù)所有錯誤的第一條

該指令為語法糖(見示例)

<input v-model="username" v-verify="username"><label v-show="$verify.$errors.username && $verify.$errors.username.length" v-text="$verify.$errors.username[0]"></label><!--等價于--><label v-verified="$verify.$errors.username"></label><!--展示所有錯誤--><label v-verified.join="$verify.$errors.username">

修飾符說明

.join 展示所有錯誤 用逗號隔開

自定義驗(yàn)證規(guī)則

var myRules={  phone:{    test:/^1[34578]/d{9}$/,    message:"電話號碼格式不正確"  },  max6:{    test:function(val){      if(val.length>6) {        return false      }      return true;    },    message:"最大為6位"  }}import Vue from "vue";import verify from "vue-verify-plugin";Vue.use(verify,{  rules:myRules});

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 萝北县| 石城县| 永昌县| 沈阳市| 克拉玛依市| 伊金霍洛旗| 德格县| 望城县| 波密县| 吕梁市| 新乡市| 个旧市| 镇坪县| 新建县| 宁海县| 琼海市| 塔城市| 思茅市| 茌平县| 汝南县| 塘沽区| 玉树县| 郯城县| 金昌市| 平谷区| 广丰县| 会宁县| 莱阳市| 登封市| 益阳市| 胶州市| 肇东市| 桃源县| 兰西县| 雷山县| 太湖县| 齐齐哈尔市| 平山县| 南安市| 手游| 鄂托克旗|