1. 表单验证
Form组件提供了表单验证的功能,只需要通过 rules 属性传入约定的验证规则,
并将Form-Item的prop属性设置为需校验的字段名即可

<el-dialog :title="title" :visible.sync="editFormVisible" width="30%" @click="closeDialog">
<el-form label-width="120px" :model="editForm" :rules="rules" ref="editForm">
<el-form-item label="文章标题" prop="title">
<el-input size="small" v-model="editForm.title" auto-complete="off" placeholder="请输入文章标题"></el-input>
</el-form-item>
<el-form-item label="文章内容" prop="body">
<el-input size="small" v-model="editForm.body" auto-complete="off" placeholder="请输入文章内容"></el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button size="small" @click="closeDialog">取消</el-button>
<el-button size="small" type="primary" class="title" @click="submitForm('editForm')">保存</el-button>
</div>
</el-dialog>

rules表单验证

rules: {
title: [{
required: true,
message: '请输入文章标题',
trigger: 'blur'
},
{
min: ,
max: ,
message: '文章标题长度在 3 到 5 个字符',
trigger: 'blur'
}
],
body: [{
required: true,
message: '请输入文章内容',
trigger: 'blur'
}]

2. CUD

<template>
<div>
<el-form :inline="true" :model="formInline" class="user-search">
<el-form-item label="搜索:">
<el-input size="small" v-model="formInline.title" placeholder="输入部门名称"></el-input>
</el-form-item>
<el-form-item>
<el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
<el-button size="small" type="primary" icon="el-icon-plus" @click="handleAdd()">添加</el-button>
</el-form-item>
</el-form>
<el-table size="small" :data="listData" border element-loading-text="拼命加载中" style="width: 100%;">
<el-table-column align="center" type="selection" min-width="">
</el-table-column>
<el-table-column sortable prop="id" label="文章ID" min-width="">
</el-table-column>
<el-table-column sortable prop="title" label="文章标题" min-width="">
</el-table-column>
<el-table-column sortable prop="body" label="文章内容" min-width="">
</el-table-column>
</el-table-column>
<el-table-column align="center" label="操作" min-width="">
<template slot-scope="scope">
<el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
<el-button size="mini" type="danger" @click="deleteUser(scope.$index, scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<el-pagination style="margin-top: 20px;" @size-change="handleSizeChange" @current-change="handleCurrentChange"
:current-page="formInline.page" :page-sizes="[10, 20, 30, 50]" :page-size="" layout="total, sizes, prev, pager, next, jumper"
:total="total">
</el-pagination> <el-dialog :title="title" :visible.sync="editFormVisible" width="30%" @click="closeDialog">
<el-form label-width="120px" :model="editForm" :rules="rules" ref="editForm">
<el-form-item label="文章标题" prop="title">
<el-input size="small" v-model="editForm.title" auto-complete="off" placeholder="请输入文章标题"></el-input>
</el-form-item>
<el-form-item label="文章内容" prop="body">
<el-input size="small" v-model="editForm.body" auto-complete="off" placeholder="请输入文章内容"></el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button size="small" @click="closeDialog">取消</el-button>
<el-button size="small" type="primary" class="title" @click="submitForm('editForm')">保存</el-button>
</div>
</el-dialog> </div>
</template> <script>
export default {
data() {
return {
listData: [],
formInline: {
page: ,
rows: ,
title: ''
},
total: ,
editForm: {
id: ,
title: '',
body: ''
},
editFormVisible: false,
title: '',
rules: {
title: [{
required: true,
message: '请输入文章标题',
trigger: 'blur'
},
{
min: ,
max: ,
message: '文章标题长度在 3 到 5 个字符',
trigger: 'blur'
}
],
body: [{
required: true,
message: '请输入文章内容',
trigger: 'blur'
}]
}
};
},
methods: {
doSearch(params) {
let url = this.axios.urls.SYSTEM_ARTICLE_LIST;
this.axios.post(url, params).then((response) => {
this.listData = response.data.result;
this.total = response.data.pageBean.total;
console.log(response); }).catch(function(error) {
console.log(error);
});
},
handleSizeChange(rows) {
this.formInline.page = ;
this.formInline.rows = rows;
this.search();
},
handleCurrentChange(page) {
this.formInline.page = page;
this.search();
},
search() {
this.doSearch(this.formInline);
},
closeDialog() { },
submitForm(formName) {
this.$refs[formName].validate((valid) => {
if (valid) {
let url;
if(this.editForm.id == ){
url = this.axios.urls.SYSTEM_ARTICLE_ADD;
}else{
url = this.axios.urls.SYSTEM_ARTICLE_EDIT;
}
this.axios.post(url,this.editForm).then((response) => {
console.log(response);
this.clearData();
this.search();
}).catch(function(error) {
console.log(error);
});
} else {
console.log('error submit!!');
return false;
}
});
},
handleAdd() {
this.clearData();
this.editFormVisible = true;
this.title = '新增文章'; },
handleEdit(index,row){
this.editFormVisible = true;
this.title = '编辑文章';
this.editForm.id = row.id;
this.editForm.title = row.title;
this.editForm.body = row.body;
},
deleteUser(index,row){
let url = this.axios.urls.SYSTEM_ARTICLE_DEL;
this.axios.post(url,{id:row.id}).then((response) => {
console.log(response);
this.clearData();
this.search();
}).catch(function(error) {
console.log(error);
});
},
clearData(){
this.editFormVisible = false;
this.title='';
this.editForm.id=;
this.editForm.title='';
this.editForm.body='';
}
},
created() {
this.doSearch({});
}
}
</script> <style> </style>

SPA项目之CRUD+表单验证的更多相关文章

  1. SPA项目开发之CRUD+表单验证

    表单验证 Form组件提供了表单验证的功能,只需要通过 rules 属性传入约定的验证规则, 并将Form-Item的prop属性设置为需校验的字段名即可 <el-form-item label ...

  2. vue表单验证:vee-validate中文提示

    官方文档:https://baianat.github.io/vee-validate/guide/ vee-validate可用于vue项目中进行表单验证,使用方法在官方API上都可以查到: 使用过 ...

  3. Vue如何使用vee-validate表单验证

    Vue项目遇到要表单验证了吧,对我来说表单验证是个很纠(dan)结(teng)的内容,各种判断凌乱到飞起.往常使用jquery的validate插件做表单验证方便吧,你也可以在Vue里引入jquery ...

  4. SPA项目开发--表单验证、增删改

    1. 表单验证 Form组件提供了表单验证的功能,只需要通过 rules 属性传入约定的验证规则,   并将Form-Item的prop属性设置为需校验的字段名即可      <el-form- ...

  5. 关于Web项目里的给表单验证控件添加结束时间不得小于开始时间的验证方法,日期转换和前台显示格式之间,还有JSON取日期数据格式转换成标准日期格式的问题

    项目里有些不同页面间的日期显示格式是不同的, 第一个问题: 比如我用日期控件WdatePicker.js导包后只需在input标签里加上onClick="WdatePicker()" ...

  6. JaveWeb 公司项目(4)----- Easyui的表单验证

    前面三篇博文讲述的是界面的搭建和数据的传输,可以看出目前我做的这个小项目已经有了一个大体的雏形,剩下的就是细节部分的打磨和一些友好的人机交互设计,今天做的是表单的验证,作为初学者,着实花了一番功夫,所 ...

  7. vue项目element-ui框架中的弹窗中的表单验证清除问题

    问题回顾: 1.vue项目的在弹窗上的form表单验证,第一次点击新增时正常,第二次新增打开弹窗后由于表单内容为空,出现验证这种情况 2.为了解决上面的情况,在执行点击新增事件加上this.$refs ...

  8. SpringBoot项目中,表单的验证操作

    在创建Springboot项目中,我们使用了表单验证操作,这一操作将极大地简化我们编程的开发 1.接收数据,以及验证 @PostMapping("/save") public Mo ...

  9. Vue项目之实现登录功能的表单验证!

    Vue项目之实现登录功能的表单验证! 步骤: 配置 Form表单验证; 1.必须给el-from组件绑定model 为表单数据对象 2 给需要验证的表单项 el-form-item 绑定 prop 属 ...

随机推荐

  1. django找不到模板的错误处理django.template.exceptions.TemplateDoesNotExist: blog/list.html

    错误提示如下图: 程序出错对于程序员而言是最常见的,一般解决的要点是看清错误提示(读懂英文很重要) 根据错误提示 blog\list.html这个文件不存在,也就是没找到资源 这个时候需要去检查有没有 ...

  2. My97DatePicker-WdatePicker日历日期插件详细示例

    <!DOCTYPE html> <html> <head> <title>排行</title> <meta charset=" ...

  3. HDFS存入文件的整个流程

    本文结合HDFS的副本和分块从宏观上描述HDFS存入文件的整个流程.HDFS体系中包含Client.NameNode.DataNode.SeconderyNameode四个角色,其中Client是客户 ...

  4. 「漏洞预警」Apache Flink 任意 Jar 包上传导致远程代码执行漏洞复现

    漏洞描述 Apache Flink是一个用于分布式流和批处理数据的开放源码平台.Flink的核心是一个流数据流引擎,它为数据流上的分布式计算提供数据分发.通信和容错功能.Flink在流引擎之上构建批处 ...

  5. Vm虚拟机最小化安装linux并配置NAT网络连接(全图)

  6. shell 脚本里的$(( ))、$( )、``与${ }的区别

    shell  脚本里的命令执行 1. 在bash中,$( )与` `(反引号)都是用来作命令替换的. 命令替换与变量替换差不多,都是用来重组命令行的,先完成引号里的命令行,然后将其结果替换出来,再重组 ...

  7. 手把手教你安装Virtualbox,安装并运行虚拟机

    一.安装VirtualBox. 官网:https://www.virtualbox.org/wiki/Downloads 首先,进入官网下载页面,单击Windows hosts 链接(图中红色方框), ...

  8. fiddler 常用命令及快捷键

    1.搜索: ?  baidu.com 2.bpu 发起请求时中断 设置断点 bpu baidu.com 取消断点:bpu 3.bpafter  收到响应后中断 设置断点:bpafter baidu.c ...

  9. Notepad++ 异常崩溃 未保存的new *文件列表没了怎么办?

    今天就遇到这种问题了,把之前写的临时代码拷贝到Notepad++,不知道啥时候脑袋一抽风强迫症犯了就把所有临时代码给未保存关闭了,然后懊恼不已,百度了一下解决办法,一下就搜到了. Notepad++是 ...

  10. 百度云盘资源 for MAC 第三方工具不限速下载

    相信大家都比较困惑,百度网盘客户端限速后一般只有几十K的下载速度,Windows有百度网盘破解版,但MAC的破解版似乎不存在,要提速的话,一般的做法是开超级会员(27元/月),身为程序员的我们,是不是 ...