参考地址:https://segmentfault.com/q/1010000003988864

github地址:https://github.com/fergaldoyle/vue-form

安装插件

cnpm install vue-form --save

使用,在main.js里加入

import VueForm from 'vue-form'

Vue.use(VueForm)

代码实战

 <template>
<div class="login__content">
<vue-form :state="formstate" v-model="formstate">
<div class="login__title">SIGN IN</div>
<div class="login__content_input username__margin_bottom">
<validate auto-label class="form-group required-field" :class="fieldClassName(formstate.name)">
<input type="text" name='name' placeholder="Username" required v-model="model.name"/>
</validate>
<field-messages name="name" v-show="isSubmit">
<!--<div class="success__msg"></div>-->
<div class="error__msg" slot="required">Username is a required field</div>
</field-messages>
</div>
<div class="login__content_input">
<validate auto-label class="required-field" :class="fieldClassName(formstate.password)">
<input type="password" name="password" placeholder="Password" required v-model="model.password" />
</validate>
<field-messages name="password" v-show="isSubmit" >
<!--<div class="success__msg"></div>-->
<div class="error__msg" slot="required">Password is a required field</div>
</field-messages> </div>
<div class="error__msg" v-if='errorMsg["fail"]'>{{errorMsg["fail"]}}</div>
<div class="login__in_part">
<div class="forgot__password">
<a >Forgot Password</a>
</div>
<div class="login__remember">
<label><input type="checkbox" v-model="isRemember" /> Remember me</label>
</div>
<div class="login__in">
<button class="signin" @click.prevent="login" >SIGN IN</button>
</div>
</div>
<div class="sign__register">Don't have an account? <a href="#" >Sign Up</a> </div>
</vue-form>
</div>
</template>
<script>
import config from '../../utils/config.js'
export default{
data(){
return{
formstate: {},
errorMsg:{},
isSubmit:false,
isRemember:true,
model:{
name:'',
password:''
}
}
},
methods:{
fieldClassName: function (field) {
if(!field) {
return '';
}
if((field.$touched || field.$submitted) && field.$valid && !this.errorMsg["fail"]) {
return 'has-success';
}
if((field.$touched || field.$submitted) && field.$invalid && this.errorMsg["fail"]) {
return 'has-danger';
}
},
login(){
this.isSubmit=true;
if(this.formstate.$valid===false){
return
}
let o={
email:this.model.name,
password:this.model.password
}
this.$axios.post(`${config.apiPreUrl}/login/getToken`, o).then((res)=>{
console.log(res.data);
})
}
}
}
</script>
<style lang="scss" >
.login__content{
width: 452px;
height: 495px;
background: white;
position: relative;
box-shadow: 0px 0px 14px #423D40;
padding: 0 44px 0 43px;
}
.login__title{
padding: 56px 0 27px 0px;
font-size: 18px;
color: #3A3A3A;
font-weight: bolder;
}
.login__content_input{
width: 365px;
position: relative;
input{
height: 48px;
padding: 0 8px;
background-color: #ffffff;
padding-left: 15px;
width: 100%;
outline: none;
font-size: 15px;
border: solid 1px #C4C4C4;
&:hover{
border: solid #C4C4C4 1px;
box-shadow:0 0 3px rgba(136,136,136,0.7);
}
}
}
.username__margin_bottom{
margin-bottom: 25px;
}
.forgot__password{
font-size: 11px;
padding: 9px 0 0 4px ;
a{
color:#E25043;
cursor: pointer;
}
}
.login__remember{
padding: 29px 0;
font-size: 11px;
color: #707D95;
font-weight: lighter;
input{
margin-top:0px !important;
margin-right: 5px;
vertical-align: middle;
}
}
.login__in_part{
padding-left: 4px;
}
.login__in{
height: 44px;
button{
width: 50%;
height: 44px;
color: #000;
border: 0;
background: #E25043;
color: #ffffff;
font-size: 12px;
}
}
.sign__register{
padding: 29px 0 0 6px;
color: #4A4A4A;
font-size: 12px;
a{
color: #E25043;
text-decoration: none;
}
}
.error__msg{
color: #E25043;
font-size: 13px;
padding: 7px 0 0 0 ;
}
.has-danger{
border: solid 1px #EB7057!important;
}
.has-success{
border: solid 1px #43C7A9 !important;
}
.has-normal{
border:solid #C4C4C4 1px!important;
}
</style>

vue-form表单验证插件的更多相关文章

  1. jquery plugin 之 form表单验证插件

    基于h5表单验证系统.扩展了对easyui组件的支持 先上图: 提示样式用到了伪对象的 {content: attr(xxx)}函数方法,实现提示信息能动态切换. 1.关键属性说明: type: 表单 ...

  2. vue form表单验证

    <el-select v-model="ruleForm.region" placeholder="请选择活动区域"> <el-option ...

  3. [php基础]PHP Form表单验证:PHP form validator使用说明

    在PHP网站开发建设中,用户注册.留言是必不可少的功能,用户提交的信息数据都是通过Form表单提交,为了保证数据的完整性.安全性,PHP Form表单验证是过滤数据的首要环节,PHP对表单提交数据的验 ...

  4. 写一个简单易用可扩展vue表单验证插件(vue-validate-easy)

    写一个vue表单验证插件(vue-validate-easy) 需求 目标:简单易用可扩展 如何简单 开发者要做的 写了一个表单,指定一个name,指定其验证规则. 调用提交表单方法,可以获取验证成功 ...

  5. vue elementui form表单验证

    最近我们公司将前端框架由easyui 改为 vue+elementui .自学vue两周 就开始了爬坑之路.业余时间给大家分享一下心得,技术新手加上第一次分享(小激动),有什么不足的地方欢迎大家指正, ...

  6. jquery validate表单验证插件-推荐

    1 表单验证的准备工作 在开启长篇大论之前,首先将表单验证的效果展示给大家.     1.点击表单项,显示帮助提示 2.鼠标离开表单项时,开始校验元素  3.鼠标离开后的正确.错误提示及鼠标移入时的帮 ...

  7. 表单验证插件之jquery.validate.js

    提到表单验证的插件,第一个想到的就是jquery.validate.js,所以小生想在这里稍微详细地说一下这款插件的具体使用方法,便于理解,我直接附上整段demo的代码(没怎么调样式,主要是看js): ...

  8. jQuery学习之:Validation表单验证插件

    http://polaris.blog.51cto.com/1146394/258781/ 最近由于公司决定使用AJAX + Struts2来重构项目,让我仔细研究一下这两个,然后集中给同事讲讲,让每 ...

  9. jquery validate表单验证插件

    1 表单验证的准备工作 在开启长篇大论之前,首先将表单验证的效果展示给大家.     1.点击表单项,显示帮助提示 2.鼠标离开表单项时,开始校验元素  3.鼠标离开后的正确.错误提示及鼠标移入时的帮 ...

  10. JS表单验证插件(支持Ajax验证)

    自己编写了一个表单验证插件,支持ajax验证,使用起来很简单. 每个需要验证的表单元素下面有一个span标签,这个标签的class有一个valid表示需要验证,如果有nullable则表示可为空:ru ...

随机推荐

  1. thinkphp的PHPexecl表格样式设置

    /** * 以下是使用示例,对于以 //// 开头的行是不同的可选方式,请根据实际需要 * 打开对应行的注释. * 如果使用 Excel5 ,输出的内容应该是GBK编码. */ //require_o ...

  2. 拓展jquery js动态添加html代码 初始化数据

    1 /** * 新增数据筛选 */ (function () { $.filterEvent = function(options){ var _this = this; var defaults = ...

  3. 混合app开发,h5页面调用ios原生APP的接口

    混合APP开发中,前端开发H5页面,不免会把兼容性拉进来,在做页面的兼容性同事,会与原生app产生一些数据交互: 混合APP开发,安卓的兼容性倒是好说,安卓使用是chrome浏览器核心,已经很好兼容H ...

  4. SQLServer 的数据分页:

    假设现在有这样的一张表:CREATE TABLE test( id int primary key not null identity, names varchar(20))然后向里面插入大约1000 ...

  5. C++学习一explicit

    explicit关键字 C++中的关键字explicit主要是用来修饰类的构造函数,被修饰的构造函数的类,不能发生相应的隐式类型转换,只能以显示的方式进行类型转换.类构造函数默认情况下声明为隐式的即i ...

  6. 30种提高mysql处理速度的方法

    1.应尽量避免在 where 子句中使用!=或<>操作符,否则将引擎放弃使用索引而进行全表扫描. 2.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉 ...

  7. padding-bottom图片自适应

    今天学了慕课网的去哪了视频轮播图的图片自适应是这么做的htm,cssl如下:为什么padding-bottom 取值62.08% 呢,因为图片的高为465px,宽为749px. 465/749 既为6 ...

  8. python网络编程之开启进程的方式

    标签(空格分隔): 开启进程的方式 multiprocessing模块介绍: python中的多线程无法利用多核优势,如果想要充分地使用多核CPU的资源(os.cpu_count()查看),在pyth ...

  9. python基础之字符串常用操作总结

    字符串的索引 s = 'ABCDLSESRF' # 索引 这两个很简单没什么说的 s1 = s[0] print(s1) # A s2 = s[2] print(s2) # C 切片 s = 'ABC ...

  10. linux 查看端口占用

    参考 https://www.cnblogs.com/wangtao1993/p/6144183.html lsof -i:8000