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

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

rules表单验证

  1. rules: {
  2. title: [{
  3. required: true,
  4. message: '请输入文章标题',
  5. trigger: 'blur'
  6. },
  7. {
  8. min: ,
  9. max: ,
  10. message: '文章标题长度在 3 到 5 个字符',
  11. trigger: 'blur'
  12. }
  13. ],
  14. body: [{
  15. required: true,
  16. message: '请输入文章内容',
  17. trigger: 'blur'
  18. }]

2. CUD

  1. <template>
  2. <div>
  3. <el-form :inline="true" :model="formInline" class="user-search">
  4. <el-form-item label="搜索:">
  5. <el-input size="small" v-model="formInline.title" placeholder="输入部门名称"></el-input>
  6. </el-form-item>
  7. <el-form-item>
  8. <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
  9. <el-button size="small" type="primary" icon="el-icon-plus" @click="handleAdd()">添加</el-button>
  10. </el-form-item>
  11. </el-form>
  12. <el-table size="small" :data="listData" border element-loading-text="拼命加载中" style="width: 100%;">
  13. <el-table-column align="center" type="selection" min-width="">
  14. </el-table-column>
  15. <el-table-column sortable prop="id" label="文章ID" min-width="">
  16. </el-table-column>
  17. <el-table-column sortable prop="title" label="文章标题" min-width="">
  18. </el-table-column>
  19. <el-table-column sortable prop="body" label="文章内容" min-width="">
  20. </el-table-column>
  21. </el-table-column>
  22. <el-table-column align="center" label="操作" min-width="">
  23. <template slot-scope="scope">
  24. <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
  25. <el-button size="mini" type="danger" @click="deleteUser(scope.$index, scope.row)">删除</el-button>
  26. </template>
  27. </el-table-column>
  28. </el-table>
  29. <el-pagination style="margin-top: 20px;" @size-change="handleSizeChange" @current-change="handleCurrentChange"
  30. :current-page="formInline.page" :page-sizes="[10, 20, 30, 50]" :page-size="" layout="total, sizes, prev, pager, next, jumper"
  31. :total="total">
  32. </el-pagination>
  33.  
  34. <el-dialog :title="title" :visible.sync="editFormVisible" width="30%" @click="closeDialog">
  35. <el-form label-width="120px" :model="editForm" :rules="rules" ref="editForm">
  36. <el-form-item label="文章标题" prop="title">
  37. <el-input size="small" v-model="editForm.title" auto-complete="off" placeholder="请输入文章标题"></el-input>
  38. </el-form-item>
  39. <el-form-item label="文章内容" prop="body">
  40. <el-input size="small" v-model="editForm.body" auto-complete="off" placeholder="请输入文章内容"></el-input>
  41. </el-form-item>
  42. </el-form>
  43. <div slot="footer" class="dialog-footer">
  44. <el-button size="small" @click="closeDialog">取消</el-button>
  45. <el-button size="small" type="primary" class="title" @click="submitForm('editForm')">保存</el-button>
  46. </div>
  47. </el-dialog>
  48.  
  49. </div>
  50. </template>
  51.  
  52. <script>
  53. export default {
  54. data() {
  55. return {
  56. listData: [],
  57. formInline: {
  58. page: ,
  59. rows: ,
  60. title: ''
  61. },
  62. total: ,
  63. editForm: {
  64. id: ,
  65. title: '',
  66. body: ''
  67. },
  68. editFormVisible: false,
  69. title: '',
  70. rules: {
  71. title: [{
  72. required: true,
  73. message: '请输入文章标题',
  74. trigger: 'blur'
  75. },
  76. {
  77. min: ,
  78. max: ,
  79. message: '文章标题长度在 3 到 5 个字符',
  80. trigger: 'blur'
  81. }
  82. ],
  83. body: [{
  84. required: true,
  85. message: '请输入文章内容',
  86. trigger: 'blur'
  87. }]
  88. }
  89. };
  90. },
  91. methods: {
  92. doSearch(params) {
  93. let url = this.axios.urls.SYSTEM_ARTICLE_LIST;
  94. this.axios.post(url, params).then((response) => {
  95. this.listData = response.data.result;
  96. this.total = response.data.pageBean.total;
  97. console.log(response);
  98.  
  99. }).catch(function(error) {
  100. console.log(error);
  101. });
  102. },
  103. handleSizeChange(rows) {
  104. this.formInline.page = ;
  105. this.formInline.rows = rows;
  106. this.search();
  107. },
  108. handleCurrentChange(page) {
  109. this.formInline.page = page;
  110. this.search();
  111. },
  112. search() {
  113. this.doSearch(this.formInline);
  114. },
  115. closeDialog() {
  116.  
  117. },
  118. submitForm(formName) {
  119. this.$refs[formName].validate((valid) => {
  120. if (valid) {
  121. let url;
  122. if(this.editForm.id == ){
  123. url = this.axios.urls.SYSTEM_ARTICLE_ADD;
  124. }else{
  125. url = this.axios.urls.SYSTEM_ARTICLE_EDIT;
  126. }
  127. this.axios.post(url,this.editForm).then((response) => {
  128. console.log(response);
  129. this.clearData();
  130. this.search();
  131. }).catch(function(error) {
  132. console.log(error);
  133. });
  134. } else {
  135. console.log('error submit!!');
  136. return false;
  137. }
  138. });
  139. },
  140. handleAdd() {
  141. this.clearData();
  142. this.editFormVisible = true;
  143. this.title = '新增文章';
  144.  
  145. },
  146. handleEdit(index,row){
  147. this.editFormVisible = true;
  148. this.title = '编辑文章';
  149. this.editForm.id = row.id;
  150. this.editForm.title = row.title;
  151. this.editForm.body = row.body;
  152. },
  153. deleteUser(index,row){
  154. let url = this.axios.urls.SYSTEM_ARTICLE_DEL;
  155. this.axios.post(url,{id:row.id}).then((response) => {
  156. console.log(response);
  157. this.clearData();
  158. this.search();
  159. }).catch(function(error) {
  160. console.log(error);
  161. });
  162. },
  163. clearData(){
  164. this.editFormVisible = false;
  165. this.title='';
  166. this.editForm.id=;
  167. this.editForm.title='';
  168. this.editForm.body='';
  169. }
  170. },
  171. created() {
  172. this.doSearch({});
  173. }
  174. }
  175. </script>
  176.  
  177. <style>
  178.  
  179. </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. mysql不等于判断时,空值过滤问题

    产生根源 比如我们有三条数据,对应的列名是delete_flag,对应的数据是'normal','delete',null. 此时我们查所有不等于delete的记录,我们期望的是两条记录 normal ...

  2. MongoDB(二):在Windows环境安装MongoDB

    1. 在Windows环境安装 1.1 MongoDB下载 要在Windows上安装MongoDB,首先打开MongoDB官网:https://www.mongodb.com/download-cen ...

  3. 微信小程序-强制手机端更新

    小程序的更新机制 开发者在管理后台发布新版本的小程序之后,如果某个用户本地有小程序的历史版本,此时打开的可能还是旧版本.微信客户端会有若干个时机去检查本地缓存的小程序有没有更新版本,如果有则会静默更新 ...

  4. gradle下mybatis自动生成框架的使用

    自动生成框架的意义 主要为了解决人为添加mapper,模型等工作,减少错误,提交效率! 添加引用build.gradle configurations { mybatisGenerator } myb ...

  5. 记一次在node.js中使用crypto的createCipheriv方法进行加密时所遇到的坑

    Node.js的crypto模块提供了一组包括对OpenSSL的哈希.HMAC.加密.解密.签名,以及验证等一整套功能的封装.具体的使用方法可以参考这篇文章中的描述:node.js_crypto模块. ...

  6. WestWild: 1.1: Vulnhub Walkthorugh

    启动界面 主机层面扫描: ╰─ nmap -p1-65535 -sV -A 10.10.202.131 Starting Nmap 7.70 ( https://nmap.org ) at 2019- ...

  7. Oracle VirtualBox安装CentOS 8

    1.下载CentOS CentOS下载地址: https://wiki.centos.org/Download 这里以CentOS8为例 选择一个比较快的地址,这里以jdcloud mirror为例 ...

  8. DSP开发程序相关问题总结

    1. 定义Class总是出错,原来是这样的class SCM_DRV_API CSERCOS{}:后来改为class CSERCOS{}:就可以了. 类的一般定义格式如下:    class < ...

  9. 【bzoj4671】异或图(容斥+斯特林反演+线性基)

    传送门 题意: 给出\(s,s\leq 60\)张图,每张图都有\(n,n\leq 10\)个点. 现在问有多少个图的子集,满足这些图的边"异或"起来后,这张图为连通图. 思路: ...

  10. Vue小练习 02

    用table标签渲染下面的数据, 最后一列为总分, 第一列为排名 scores = [ {name: 'Bob', math: 97, chinese: 89, english: 67}, {name ...