vue view 表单验证正常逻辑
<template>
<Form ref="formInline" :model="formInline" :rules="ruleInline" inline>
<FormItem prop="user">
<InputNumber :max="100" :min="0" step="1" v-model="formInline.user"></InputNumber>
</FormItem>
<FormItem prop="password">
<InputNumber :max="100" :min="0" step="1" v-model="formInline.password"></InputNumber>
</FormItem>
<FormItem>
<Button type="primary" @click="handleSubmit('formInline')">登录</Button>
</FormItem>
</Form>
</template>
<script>
export default {
data () {
const user = (rule, value, callback) => {
if (value == 0) {
callback(new Error('用户名不能为空'));
} else {
callback();
}
};
const password = (rule, value, callback) => {
if (value == 0) {
callback(new Error('密码不能为空'));
} else {
callback();
}
};
return {
formInline: {
user: 0,
password: 0
},
ruleInline: {
user: [
{ required: true, validator: user, trigger: 'change' }
],
password: [
{ required: true, validator: password, trigger: 'change' },
]
}
}
},
methods: {
handleSubmit(name) {
this.$refs[name].validate((valid) => {
if (valid) {
this.$Message.success('Success!');
} else {
this.$Message.error('Fail!');
}
})
}
}
}
</script>
vue view 表单验证正常逻辑的更多相关文章
- 使用vue做表单验证
<template> <Form ref="formInline" :model="formInline" :rules="rule ...
- vue+element 表单验证
效果图 <template> <div class="formValidator"> <div v-for="(item,index) in ...
- vue element 表单验证不通过,滚动到固对应位置
我们在使用elementIUI实现表单验证,内容比较多的时候,提示内容会被遮挡,这时候用户不清楚什么情况,还会连续点击提交按钮.这个时候需求来啦:我们需要在表单验证不通过的时候,页面滚动到对应的位置. ...
- vue:表单验证时,trigger的值什么时候选blur什么时候选change
对el-input输入框的验证,trigger的值选blur,即失去焦点时进行验证. 下拉框(el-select).日期选择器(el-date-picker).复选框(el-checkbox).单选框 ...
- vue form表单验证
<el-select v-model="ruleForm.region" placeholder="请选择活动区域"> <el-option ...
- 好用的表单验证工具 vuelidate
Vue validation(表单验证)--vuelidate 表单是用户那里收集的数据的工具.如果它没有收集到你需要的数据,或者收集到的数据不对,那么你的表单就没有达到它的目的.这就是为什么我们需要 ...
- jquery validate表单验证插件-推荐
1 表单验证的准备工作 在开启长篇大论之前,首先将表单验证的效果展示给大家. 1.点击表单项,显示帮助提示 2.鼠标离开表单项时,开始校验元素 3.鼠标离开后的正确.错误提示及鼠标移入时的帮 ...
- jquery validate表单验证插件
1 表单验证的准备工作 在开启长篇大论之前,首先将表单验证的效果展示给大家. 1.点击表单项,显示帮助提示 2.鼠标离开表单项时,开始校验元素 3.鼠标离开后的正确.错误提示及鼠标移入时的帮 ...
- Django中的Form表单验证
回忆一下Form表单验证的逻辑: 前端有若干个input输入框,将用户输入内容,以字典传递给后端. 后端预先存在一个Form表单验证的基类,封装了一个检测用户输入是否全部通过的方法.该方法会先定义好错 ...
随机推荐
- Even and Odd Functions
\subsection{Even and Odd Functions} For a function $f$ in the form $y=f(x)$, we describe its type of ...
- MLLib实践Naive Bayes
引言 本文基于Spark (1.5.0) ml库提供的pipeline完整地实践一次文本分类.pipeline将串联单词分割(tokenize).单词频数统计(TF),特征向量计算(TF-IDF),朴 ...
- AndroidPn推送测试
服务器搭建好了之后,往客户端推送.按照里面自带的一个client,可以分别在模拟器和真机上分别测试,不过由于这个框架真的不是很完善,会遇到各种问题. (1) 其中还遇到了一个安卓模拟器的问题,启动模拟 ...
- Android开发基于百度地图的乘车助手
写在前面: 出去玩免不了挤公交.等地铁,不知道乘车方案当然不行,用官方APP吧,缺点一大堆,手机浏览器在线查的话既慢又麻烦...为了解决这些问题,我们来做一个简版的出行助手,嘛嘛再也不用担心我会迷路了 ...
- From Alpha to Gamma (I)
What we think of as conventional alpha-blending is basically wrong. --Tom Forsyth 前段时间在Amazon上淘的三本二手 ...
- Comparable接口——容器中自定义类排序
1.容器TreeMap,默认根据Key对象中某个属性的从小到大排列元素. (1)如下代码示例,Key是整型数字,所以按照其从小到大的顺序排列 public class TestTreeMap { pu ...
- 673. Number of Longest Increasing Subsequence
Given an unsorted array of integers, find the number of longest increasing subsequence. Example 1: I ...
- Graph-684. Redundant Connection
In this problem, a tree is an undirected graph that is connected and has no cycles. The given input ...
- ssh 登陆 端口转发
man ssh ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec] [-D [bind_address:]port] ...
- 刚才在windows下发现拖拽不了文件了
百度了下 摁了两下esc就可以了.以下是百度得到的答案 按几下Esc目的是:没按前ESC键[接触不好]或[键不灵]或其他原因导致ESC处于[按下]状态,这样鼠标就会拖不了文件,点击菜单也会马上消失, ...