当前位置:网站首页>Crud+ form verification for spa project development
Crud+ form verification for spa project development
2022-06-22 22:09:00 【Gu Bei!】
One 、 Form validation
Articles.vue:
1、 Editing interface :
<!-- Editing interface -->
<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=" Article title " prop="title">
<el-input size="small" v-model="editForm.title" auto-complete="off" placeholder=" Please enter the title of the article "></el-input>
</el-form-item>
<el-form-item label=" Article content " prop="body">
<el-input size="small" v-model="editForm.body" auto-complete="off" placeholder=" Please enter the content of the article "></el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button size="small" @click="closeDialog"> Cancel </el-button>
<el-button size="small" type="primary" class="title" @click="submitForm('editForm')"> preservation </el-button>
</div>
</el-dialog>
2、 Defining variables
title: '',
editFormVisible: false,
3、 Method
data:
editForm: {
},
// Pass in the agreed validation rules
rules: {
title: [{
required: true,
message: ' Please enter the title of the article ',
trigger: 'blur'
},
{
min: 3,
max: 5,
message: ' The length is in 3 To 5 Characters ',
trigger: 'blur'
}
],
body: [{
required: true,
message: ' Please enter the content of the article ',
trigger: 'blue'
}]
}
methods:
// Cancel pop-up
closeDialog() {
},
handleEdit(){
// pop-up
this.editFormVisible=true;
},
// Verification method
submitForm(formName) {
this.$refs[formName].validate((valid) => {
if (valid) {
alert('submit!');
} else {
console.log('error submit!!');
return false;
}
});
},
When form validation is required , Remember to mount the verification rules in the form :
4、 Exhibition
①、 Code display :
<template>
<div>
<!-- This is the article list component -->
<!-- Search filter -->
<el-form :inline="true" :model="formInline" class="user-search">
<el-form-item label=" Search for :">
<el-input size="small" v-model="formInline.title" placeholder=" Article title "></el-input>
</el-form-item>
<el-form-item>
<el-button size="small" type="primary" icon="el-icon-search" @click="search"> Search for </el-button>
<el-button size="small" type="primary" icon="el-icon-plus" @click="handleEdit()"> add to </el-button>
</el-form-item>
</el-form>
<!-- list -->
<el-table size="small" :data="listData" highlight-current-row border element-loading-text=" Desperately loading "
style="width: 100%;">
<el-table-column align="center" type="selection" width="60">
</el-table-column>
<el-table-column sortable prop="id" label=" article ID" width="300">
</el-table-column>
<el-table-column sortable prop="title" label=" Article title " width="300">
</el-table-column>
<el-table-column sortable prop="body" label=" Article content " width="300">
</el-table-column>
<!-- <el-table-column align="center" label=" operation " min-width="300">
<template slot-scope="scope">
<el-button size="mini" @click="handleEdit(scope.$index, scope.row)"> edit </el-button>
<el-button size="mini" type="danger" @click="deleteUser(scope.$index, scope.row)"> Delete </el-button>
</template>
</el-table-column> -->
</el-table>
<!-- Pagination bar -->
<el-pagination style="margin-top: 20px;" @size-change="handleSizeChange" @current-change="handleCurrentChange"
:current-page="formInline.page" :page-sizes="[10, 20, 30, 50]" :page-size="100"
layout="total, sizes, prev, pager, next, jumper" :total="formInline.total">
</el-pagination>
<!-- Editing interface -->
<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=" Article title " prop="title">
<el-input size="small" v-model="editForm.title" auto-complete="off" placeholder=" Please enter the title of the article "></el-input>
</el-form-item>
<el-form-item label=" Article content " prop="body">
<el-input size="small" v-model="editForm.body" auto-complete="off" placeholder=" Please enter the content of the article "></el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button size="small" @click="closeDialog"> Cancel </el-button>
<el-button size="small" type="primary" class="title" @click="submitForm('editForm')"> preservation </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
export default {
name: 'Articles',
data() {
return {
listData: [],
title: '',
editFormVisible: false,
formInline: {
page: 1,
rows: 10,
total: 0,
title: ''
},
editForm: {
},
// Pass in the agreed validation rules
rules: {
title: [{
required: true,
message: ' Please enter the title of the article ',
trigger: 'blur'
},
{
min: 3,
max: 5,
message: ' The length is in 3 To 5 Characters ',
trigger: 'blur'
}
],
body: [{
required: true,
message: ' Please enter the content of the article ',
trigger: 'blue'
}]
}
}
},
methods: {
handleSizeChange(rows) {
console.log(" The amount of data queried on the current page :" + rows)
this.formInline.page = 1;
this.formInline.rows = rows;
this.search();
},
handleCurrentChange(page) {
console.log(" The current page is :" + page)
this.formInline.page = page;
this.search();
},
// Cancel pop-up
closeDialog() {
},
handleEdit() {
// pop-up
this.editFormVisible = true;
},
// Verification method
submitForm(formName) {
this.$refs[formName].validate((valid) => {
if (valid) {
alert('submit!');
} else {
console.log('error submit!!');
return false;
}
});
},
// Inquire about
doSearch(param) {
// Get the data
let url = this.axios.urls.SYSTEM_ARTICLE_LIST;
// The arrow function solves this Pointer pollution problem
this.axios.post(url, param).then((resp) => {
console.log(resp);
this.listData = resp.data.result;
this.formInline.total = resp.data.pageBean.total;
}).catch(function(error) {
console.log(error);
});
this.$root.Bus.$on("collapsed-aside", (v) => {
this.collapsed = v;
});
},
search() {
this.doSearch(this.formInline);
}
},
// Set the value :
created() {
this.doSearch({});
}
}
</script>
<style>
</style>
②、 Effect display :

Two 、 Methods of addition, deletion and modification
Add, delete and modify buttons :
<el-table-column align="center" label=" operation " min-width="300">
<template slot-scope="scope">
<el-button size="mini" @click="handleEdit(scope.$index, scope.row)"> edit </el-button>
<el-button size="mini" type="danger" @click="deleteUser(scope.$index, scope.row)"> Delete </el-button>
</template>
</el-table-column>
1、 edit
<script>
export default {
name: 'Articles',
data() {
return {
editForm: {
title:'',
body:'',
id:0
}
}
},
methods: {
// Clear the data in the add box , Make the data not echoed when adding
clearData(){
this.editFormVisible = false;
this.title='';
this.editForm.id=0;
this.editForm.title='';
this.editForm.body='';
},
// Cancel pop-up
closeDialog() {
this.clearData();
},
handleEdit(index,row) {
this.clearData();
// pop-up
this.editFormVisible = true;
// Echo when modifying
if(row){
this.title=' Edit window ';
this.editForm.id=row.id;
this.editForm.title=row.title;
this.editForm.body=row.body;
}else{
this.title=' New window ';
}
}
}
Front and back interaction :
submitForm(formName) {
this.$refs[formName].validate((valid) => {
if (valid) {
let url;
if(this.editForm.id==0){
url=this.axios.urls.SYSTEM_ARTICLE_ADD;
}else{
url=this.axios.urls.SYSTEM_ARTICLE_EDIT;
}
this.axios.post(url, this.editForm).then((resp)=> {
console.log(resp);
// Inquire about
this.clearData();
this.search();
}).catch(function(error) {
console.log(error);
});
} else {
console.log('error submit!!');
return false;
}
});
}
Editing interface :

Add interface :

2、 Delete
// Delete
deleteUser(index, row) {
this.editForm.id=row.id;
let url = this.axios.urls.SYSTEM_ARTICLE_DEL;
this.axios.post(url, this.editForm).then((resp) => {
console.log(resp);
// Inquire about
this.clearData();
this.search();
}).catch(function(error) {
console.log(error);
});
}
3、 Content display
<template>
<div>
<!-- This is the article list component -->
<!-- Search filter -->
<el-form :inline="true" :model="formInline" class="user-search">
<el-form-item label=" Search for :">
<el-input size="small" v-model="formInline.title" placeholder=" Article title "></el-input>
</el-form-item>
<el-form-item>
<el-button size="small" type="primary" icon="el-icon-search" @click="search"> Search for </el-button>
<el-button size="small" type="primary" icon="el-icon-plus" @click="handleEdit()"> add to </el-button>
</el-form-item>
</el-form>
<!-- list -->
<el-table size="small" :data="listData" highlight-current-row border element-loading-text=" Desperately loading "
style="width: 100%;">
<el-table-column align="center" type="selection" width="60">
</el-table-column>
<el-table-column sortable prop="id" label=" article ID" width="300">
</el-table-column>
<el-table-column sortable prop="title" label=" Article title " width="300">
</el-table-column>
<el-table-column sortable prop="body" label=" Article content " width="300">
</el-table-column>
<el-table-column align="center" label=" operation " min-width="300">
<template slot-scope="scope">
<el-button size="mini" @click="handleEdit(scope.$index, scope.row)"> edit </el-button>
<el-button size="mini" type="danger" @click="deleteUser(scope.$index, scope.row)"> Delete </el-button>
</template>
</el-table-column>
</el-table>
<!-- Pagination bar -->
<el-pagination style="margin-top: 20px;" @size-change="handleSizeChange" @current-change="handleCurrentChange"
:current-page="formInline.page" :page-sizes="[10, 20, 30, 50]" :page-size="100"
layout="total, sizes, prev, pager, next, jumper" :total="formInline.total">
</el-pagination>
<!-- Editing interface -->
<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=" Article title " prop="title">
<el-input size="small" v-model="editForm.title" auto-complete="off" placeholder=" Please enter the title of the article "></el-input>
</el-form-item>
<el-form-item label=" Article content " prop="body">
<el-input size="small" v-model="editForm.body" auto-complete="off" placeholder=" Please enter the content of the article "></el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button size="small" @click="closeDialog"> Cancel </el-button>
<el-button size="small" type="primary" class="title" @click="submitForm('editForm')"> preservation </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
export default {
name: 'Articles',
data() {
return {
listData: [],
title: '',
editFormVisible: false,
formInline: {
page: 1,
rows: 10,
total: 0,
title: ''
},
editForm: {
title: '',
body: '',
id: 0
},
// Pass in the agreed validation rules
rules: {
title: [{
required: true,
message: ' Please enter the title of the article ',
trigger: 'blur'
},
{
min: 3,
max: 5,
message: ' The length is in 3 To 5 Characters ',
trigger: 'blur'
}
],
body: [{
required: true,
message: ' Please enter the content of the article ',
trigger: 'blue'
}]
}
}
},
methods: {
handleSizeChange(rows) {
console.log(" The amount of data queried on the current page :" + rows)
this.formInline.page = 1;
this.formInline.rows = rows;
this.search();
},
handleCurrentChange(page) {
console.log(" The current page is :" + page)
this.formInline.page = page;
this.search();
},
// Clear the data in the add box , Make the data not echoed when adding
clearData() {
this.editFormVisible = false;
this.title = '';
this.editForm.id = 0;
this.editForm.title = '';
this.editForm.body = '';
},
// Cancel pop-up
closeDialog() {
this.clearData();
},
handleEdit(index, row) {
this.clearData();
// pop-up
this.editFormVisible = true;
// Echo when modifying
if (row) {
this.title = ' Edit window ';
this.editForm.id = row.id;
this.editForm.title = row.title;
this.editForm.body = row.body;
} else {
this.title = ' New window ';
}
},
// Delete
deleteUser(index, row) {
this.editForm.id=row.id;
let url = this.axios.urls.SYSTEM_ARTICLE_DEL;
this.axios.post(url, this.editForm).then((resp) => {
console.log(resp);
// Inquire about
this.clearData();
this.search();
}).catch(function(error) {
console.log(error);
});
},
// Verification method
submitForm(formName) {
this.$refs[formName].validate((valid) => {
if (valid) {
let url;
if (this.editForm.id == 0) {
url = this.axios.urls.SYSTEM_ARTICLE_ADD;
} else {
url = this.axios.urls.SYSTEM_ARTICLE_EDIT;
}
this.axios.post(url, this.editForm).then((resp) => {
console.log(resp);
// Inquire about
this.clearData();
this.search();
}).catch(function(error) {
console.log(error);
});
} else {
console.log('error submit!!');
return false;
}
});
},
// Inquire about
doSearch(param) {
// Get the data
let url = this.axios.urls.SYSTEM_ARTICLE_LIST;
// The arrow function solves this Pointer pollution problem
this.axios.post(url, param).then((resp) => {
console.log(resp);
this.listData = resp.data.result;
this.formInline.total = resp.data.pageBean.total;
}).catch(function(error) {
console.log(error);
});
this.$root.Bus.$on("collapsed-aside", (v) => {
this.collapsed = v;
});
},
search() {
this.doSearch(this.formInline);
}
},
// Set the value :
created() {
this.doSearch({});
}
}
</script>
<style>
</style>
边栏推荐
- Lesson 018: function: flexible is powerful after class test questions and answers
- Fegin的解析
- PMP Exam admission ticket problems and precautions in June, which must be read by candidates
- LeetCode#20. Valid parentheses
- 大不列颠泰迪熊加入PUBG 手游
- 第029讲:文件:一个任务 | 课后测试题及答案
- 6-1 二叉搜索树的操作集
- Implementation of breadth traversal adjacency matrix of 6-6 graph
- SPA项目开发之首页导航+左侧菜单
- Lesson 031: permanent storage: pickle a jar of delicious pickles | after class test questions and answers
猜你喜欢

In 2022, the "product innovation and achievement transformation" training camp of Chaoyang District Science and technology innovation class was successfully completed

什么是数据资产?数据资产管理应该如何落地?

Optimization solver | gurobi's Mvar class: a sharp tool for matrix modeling and an alternative solution to dual problems (with detailed cases and codes attached)

SPA项目开发之登录注册

Lesson 033: exception handling: you can't always be right 2 | after class test questions and answers

(duc/ddc) digital up mixing / quadrature down mixing principle and MATLAB simulation

Cvpr2022 𞓜 feature decoupling learning and dynamic fusion for re captured images
A hundred lines of code to realize reliable delay queue based on redis

二级造价工程师考前必备15个知识点来了!祝你旗开得胜!
![DACL output on Jerry's hardware, DAC output sound of left and right channels [chapter]](/img/8a/ce164a5538bd8edf10eba5e4e8abe6.png)
DACL output on Jerry's hardware, DAC output sound of left and right channels [chapter]
随机推荐
VS代码一键整理快捷键
牛客 52次月赛 C 说谎的机器 (区间赋值操作由O(n^2)转为O(n)的复杂度)
Android kotlin SP DP to PX
An example of 89 Oracle SQL writing and optimizer defects
The second harmonyos application development training
6月PMP考试准考证问题及注意事项,考生必读
第028讲:文件:因为懂你,所以永恒 | 课后测试题及答案【无标题】
6月25日PMI认证考点防疫要求及考场安排
LeetCode#20. Valid parentheses
第027讲:集合:在我的世界里,你就是唯一 | 课后测试题及答案
90- review of several recently optimized Oracle databases
KDD'22 | 阿里: 基于EE探索的精排CTR预估
The interception of Chinese and English strings in Oracle database is different
第032讲:异常处理:你不可能总是对的 | 课后测试题及答案
微软 Edge 浏览器将支持网络测速,内置计算器和单位转换工具
2022年6月25日PMP考试通关宝典-6
ACM. Hj24 chorus ●●
sitl_gazebo/include/gazebo_opticalflow_plugin.h:43:18: error: ‘TRUE’ was not declared in this scope
Jericho uses DP and DM for IO key detection [chapter]
NiO copy file call getchannel method transferfrom()