注册

1 安装:
npm install vee-validate --save
2.mian.js 填写
import Vue from 'vue'
import VeeValidate, {Validator} from 'vee-validate';
import zh from 'vee-validate/dist/locale/zh_CN'; Validator.addLocale(zh); const config = {
locale: 'zh_CN'
}; Vue.use(VeeValidate,config);
 1 <form @submit.prevent="validateBeforeSubmit">
2 <div class="column is-12">
3 <label class="label">手机:</label>
4 <p class="control has-icon has-icon-right">
5 <input name="phone" v-model="phone" v-validate="'required|phone'" data-first-as="Firsts Name" :class="{'input': true, 'is-danger': errors.has('phone') }" type="text" placeholder="手机">
6 <i v-show="errors.has('phone')" class="fa fa-warning"></i>
7 <span v-show="errors.has('phone')" class="help is-danger">{{ errors.first('phone') }}</span>
8 </p>
9 </div>
10 <div class="column is-12">
11 <label class="label">邮箱:</label>
12 <p class="control has-icon has-icon-right">
13 <input name="email" v-model="email" v-validate="'required|email'" data-first-as="Firsts Name" :class="{'input': true, 'is-danger': errors.has('email') }" type="text" placeholder="邮箱">
14 <i v-show="errors.has('email')" class="fa fa-warning"></i>
15 <span v-show="errors.has('email')" class="help is-danger">{{ errors.first('email') }}</span>
16 </p>
17 </div>
18 <div class="column is-12">
19 <label class="label">密码:</label>
20 <p class="control has-icon has-icon-right">
21 <input name="pwd" v-model="pwd" v-validate="'required|pwd|min:10'" data-first-as="Firsts Name" :class="{'input': true, 'is-danger': errors.has('pwd') }" type="password" placeholder="密码">
22 <i v-show="errors.has('pwd')" class="fa fa-warning"></i>
23 <span v-show="errors.has('pwd')" class="help is-danger">{{ errors.first('pwd') }}</span>
24 </p>
25 </div>
26 <div class="column is-12">
27 <label class="label">确认密码:</label>
28 <p class="control has-icon has-icon-right">
29 <input name="chepwd" v-model="chepwd" v-validate="'required|chepwd|min:10'" data-first-as="Firsts Name" :class="{'input': true, 'is-danger': errors.has('chepwd') }" type="password" placeholder="密码">
30 <i v-show="errors.has('chepwd')" class="fa fa-warning"></i>
31 <span v-show="errors.has('chepwd')" class="help is-danger">{{ errors.first('chepwd') }}</span>
32 </p>
33 </div>
34 <div class="column is-12">
35 <p class="control">
36 <button class="button is-primary" type="submit">Submit</button>
37 </p>
38 </div>
39 </form>
<script>
import { Validator } from 'vee-validate';
export default {
components: {},
name: 'form-example',
data: () => ({
phone: '',
email: '',
pwd: '',
chepwd: ''
}),
created() {
const dictionary = {
zh_CN: {
messages: {
email: () => '邮箱格式错误。',
required: (field) => "不能为空" + field, //替换 “ 必须 ” 关键字
},
attributes: {
//email: '不能为空'
}
}
};
this.$validator.updateDictionary(dictionary);
Validator.extend('phone', {
messages: {
zh_CN: field => field + '必须是11位手机号码',
},
validate: value => {
return value.length == 11 && /^((13|14|15|17|18)[0-9]{1}\d{8})$/.test(value)
}
});
Validator.extend('pwd', {
messages: {
zh_CN: field => field + '密码不能少于十位数',
},
validate: value => {
return value;
}
});
Validator.extend('chepwd', {
messages: {
zh_CN: field => field + '两次密码不一致',
},
validate: value => {
if(this.chepwd == this.pwd){
return value
}else{
return false;
}
}
});
},
methods: {
validateBeforeSubmit() {
this.$validator.validateAll().then((result) => {
if(result) { // eslint-disable-next-line
alert('From Submitted!');
return;
}
alert('Correct them errors!');
});
}
}
};
</script>
推荐阅读:
文档:http://vee-validate.logaretm.com/localization.html
官方例子:http://vee-validate.logaretm.com/examples.html
参考出处:http://www.jianshu.com/p/2a456e31c581

  

VeeValidate 注册实例的更多相关文章

  1. Node.js_express_中间件 middleware_登录/注册实例源代码

    静态资源: 都写死了的资源,如 css,html 解析规则: 所有路由和中间件都在一个数组中,js 引擎会按照代码先后顺序添加路由和中间件 当请求发送到服务器时,服务器获取当前的请求信息(请求方式.请 ...

  2. Vue学习之路之登录注册实例代码

    Vue学习之路之登录注册实例代码:https://www.jb51.net/article/118003.htm vue项目中路由验证和相应拦截的使用:https://blog.csdn.net/wa ...

  3. vue-cli——vue-resource登录注册实例

    前言 使用vue-resource请求接口非常方便,在使用前需安装vue-resource依赖并在入口文件main.js中声明. 实例功能简述 本实例只有简单的两个模块:登录和注册,主要演示如何用vu ...

  4. C# Ioc 接口注册实例以及注入MVC Controller

    当弄一个小程序时,就忽略了使用Ioc这种手段,作为一个帅气程序员,代码规范,你懂的~,废话不多说,快速搭建一个Ioc接口实例以及直接注入到 MVC Controller 构造函数中如下: MVC in ...

  5. Django——13 Auth系统 登陆注册实例 权限的实现

    Django Auth系统中的表 注册登陆实例 权限的实现 登陆权限 操作权限 组操作  Auth系统中的表 从表的名称我们就能看出,auth_user,auth_group,auth_permiss ...

  6. php+jquery注册实例

    写了一个简单的PHP+jQuery注册模块,需要填写的栏目包括用户名.邮箱.密码.重复密码和验证码,其中每个栏目需要具备的功能和要求如下图: 在做这个模块的时候,很大程度上借鉴了网易注册( http: ...

  7. ASP.NET简单登录注册实例

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx. ...

  8. python实现用户登录、注册实例

    python面向函数式编程,模拟用户登录验证.注册的代码实现. 主要有以下两个文件: 1.user.txt文档文件,相当于数据库的用户信息表,主要是记录用户名和密码. 注意:1)此文档需要与.py文件 ...

  9. Django登录(含随机生成图片验证码)注册实例

    登录,生成随机图片验证码 一.登录 - 随机生成图片验证码 1.随机生成验证码 Python随机生成图片验证码,需要使用PIL模块,安装方式如下: pip3 install pillow 1)创建图片 ...

  10. Json与Ajax(注册实例)

    需要在服务器上进行哈 jquery的ajax方法: // jquery请求 $.ajax({ url: "./server/slider.json", type: "po ...

随机推荐

  1. Datax-web入门配置与启动

    在idea中启动Datax-web 需要先将Datax在本地安装,可以参考这篇文章(datax在win10中的安装) 1.从github上拉取源码 https://github.com/WeiYe-J ...

  2. git提交命令

    链接:https://www.waimaiguai.com/technology/article/5425017来源:外卖怪 外卖怪技术学习git更新代码命令2022-08-17 02:56:11gi ...

  3. fread()函数读文本文件重复读最后一个字符问题【已解决】

    对文本文件读写时遇到一个问题,fread()读所有内容的时候文件的最后一个字符总会重复读,我的代码如下: FILE* file = nullptr; fopen_s(&file, " ...

  4. mysql查询数据是否连续增长

    记录一次比较查询,需求是比较内容是否一次比一次高,用来作为标签依据 大致问题如下 简化: 班级中有若干人,若干次考试.需要查询某人在考试时成绩越来越好(分数是每次都有增长) 思路: 1.使用group ...

  5. react fiber 的运行机制

    前言 1. 不同的元素类型决定不同的任务类型 2. react 的元素类型有 class component , function component ,Dom nodes, portal等等 要理解 ...

  6. js检测数组是否有重复的数据,

    function(arr){ let hash={} for (const key in arr){ if(hash[arr[key]]){ return true } hash[arr[key]]= ...

  7. 合格できる日本語能力試験, N1.PDF

    书本详情 合格できる日本語能力試験, N1种类:Languages - Japanese Language Reference年:2010出版:Shohan.出版社:Aruku语言:japanese页 ...

  8. 关于MYSQL知识点复习

    关于MYSQL关联查询JOIN:   https://www.cnblogs.com/withscorpion/p/9454490.html

  9. [3] ScanRefer论文精读 3DVisual Grounding开山之作

    论文名称:ScanRefer: 3D Object Localization in RGB-D Scans using Natural Language 这篇文章最主要的工作,我觉得是两个,第一,提出 ...

  10. props其他-混入mixin-插件-elementui使用-localStorage系列-vueRouter-vuex

    目录 props其他-混入mixin-插件-elementui使用-localStorage系列-vueRouter-vuex 今日内容概要 今日内容详细 1 props其他 2 混入mixin 3 ...