ElementUI实现el-form表单重置功能按钮⽬录
业务场景:
效果演⽰:
业务场景:
使⽤el-form时,点击重置按钮或者取消按钮时会实现表单重置效果。
重置功能按钮功能实现详细步骤:
第⼀:⾸先给el-form添加ref属性。
<el-form :inline="true" :model="queryParams" ref="queryForm">
第⼆:在点击重置按钮执⾏的⽅法中,执⾏如下功能代码⽚段
reset(){
# 重新设置请求参数实体属性
this.queryParams = {
memberName: undefined,
typeId: undefined,
};
# 指定表单属性值重置
this.$refs["form" ].resetFields();
}
效果演⽰:
默认展⽰页:
检索效果页:
Vue页⾯源码:
<style>
</style>
<template>
<div>
<el-col :span="19">
<el-form :inline="true" :model="queryParams" ref="queryForm">
<el-form-item label="姓名">
<el-input v-model="berName" placeholder="姓名"></el-input>
</el-form-item>
<el-form-item >
<div >
<!--⾃定义searchHandler函数-->
<el-button type="primary" @click="searchHandler">查询</el-button>
<!---->
<el-button type="primary" @click="reset">重置</el-button>
</div>
</el-form-item>
</el-form>
</el-col>
<p >
<el-button type="primary" @click="dialogFormAdd = true">添加</el-button>
</p>
<el-row>
<el-table
:data="tableData"
>
<el-table-column
v-for="(data,index) in tableHeader"
:key="index"
:prop="data.prop"
:label="data.label"
:min-width="data['min-width']"
:align="data.align">
</el-table-column>
<el-table-column
prop="memberSex"
label="性别">
<template slot-scope="scope">{{ berSex === 1 ? '男' : '⼥' }}</template>
elementui登录界面</el-table-column>
<el-table-column
prop="memberStatic"
label="会员状态">
<template slot-scope="scope">{{ berStatic === 1 ? '正常' : '不正常' }}</template> </el-table-column>
<el-table-column
label="操作"
min-width="240">
<template slot-scope="scope">
<el-button type="primary" size="mini" @click="toEdit(scope)">修改</el-button>
<el-button type="danger" size="mini" @click="deleteMember(scope)">删除</el-button>
</template>
</el-table-column>
</el-table>
<br>
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="pagination.pageIndex"
:page-sizes="[5, 10, 20, 30, 40]"
:page-size=pagination.pageSize
layout="total, sizes, prev, pager, next, jumper"
:
al>
</el-pagination>
</el-row>
<el-dialog title="添加学⽣" :visible.sync="dialogFormAdd">
<el-form :model="member">
<el-form-item label="姓名" >
<div slot="footer" class="dialog-footer">
<el-button @click="dialogFormAdd = false">取消</el-button>
<el-button type="primary" @click="add(student)">确定</el-button>
</div>
</el-dialog>
<el-dialog title="修改学⽣" :visible.sync="dialogFormEdit">
<el-form :model="member">
<el-form-item label="姓名" >
<el-input v-model="berName" auto-complete="off"></el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogFormEdit = false">取消</el-button>
<el-button type="primary" @click="edit(student)">确定</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
export default{
name: 'member',
data () {
return {
tableData: [],
dialogFormEdit: false,
dialogFormAdd:false,
member: {
memberId: '',
memberName: '',
memberPhone: '',
memberAge: '',
typeName: '',
nenberDate: '',
memberStatic:'',
memberbalance:'',
memberxufei:''
},
queryParams:{
memberName:'',
typeId:''
},
pagination: {
pageIndex: 1,
pageSize: 10,
total: 0,
},
tableHeader: [
{
prop: 'memberId',
label: '会员编号',
align: 'left'
},
{
prop: 'memberName',
label: '名称',
align: 'left'
},
{
prop: 'memberPhone',
label: '电话',
align: 'left'
},
{
prop: 'memberAge',
label: '年龄',
align: 'left'
},
{
prop: 'peName',
label: '卡类型',
align: 'left'
},
{
prop: 'nenberDate',
label: '录⼊⽇期',
align: 'left'
},
{
prop: 'memberbalance',
label: '会员余额',
align: 'left'
},
{
prop: 'memberxufei',
label: '到期⽇期',
align: 'left'
}
]
}
},
methods: {
init () {
var self = this
this.$axios({
method:'post',
url:'/menber/query',
data:{"pageNumber":this.pagination.pageIndex,"pageSize":this.pagination.pageSize,"ktype": 0},
self.tableData = ws;
})
.catch(function (error) {
console.log(error)
})
},
handleSizeChange(val) {
this.pagination.pageSize = val;
this.pagination.pageIndex = 1;
this.init();
},
handleCurrentChange(val) {
this.pagination.pageIndex = val;
this.init();
},
add (student) {
this.$axios({
method:'post',
url:'/student/insert',
data:{'name': student.name, 'sex':student.sex,'age':student.age,'college':llege,'className':student.className},
headers:{
'Content-Type':'application/json;charset=utf-8' //改这⾥就好了
}
}).then(res => {
this.$message.success('添加成功')
this.dialogFormAdd = false
this.init()
})
.catch(function (error) {
console.log(error)
})
},
toEdit (scope) {
this.student.sid = w.sid
this.student.name = w.name
this.student.sex = w.sex
this.student.age = w.age
this.dialogFormEdit = true
},
edit (student) {
var params ={
'sid' : student.sid,
'name' : student.name,
'sex' : student.sex,
'age' : student.age
}
this.$axios({
method:'post',
url:'/student/update',
data:params,
headers:{
'Content-Type':'application/json;charset=utf-8' //改这⾥就好了
}
}).then(res => {
this.$message.success('修改成功')
this.dialogFormEdit = false
this.init()
}).catch(function (error) {
console.log(error)
})
},
deleteMember (scope) {
debugger;
if (!berId) {
this.tableData.splice(scope.$index, 1)
} else {
this.$confirm('确认是否删除', '提⽰', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
center: true
})
.then(() => {
console.w.memberId)
this.$('/menber/delete/' + berId).then(res => {
this.$message.success('删除成功')
this.init()
})
.catch(function (error) {
console.log(error)
})
})
.catch(() => {
this.$message({
type: 'info',
message: '已取消删除'
})
})
}
},
searchHandler() {
var self = this
this.$axios({
method:'post',
url:'/menber/query',
data:{"pageNumber":this.pagination.pageIndex,"pageSize":this.pagination.pageSize,"ktype": 0, "hyname":berName},
self.tableData = ws;
})
.catch(function (error) {
console.log(error)
})
},
reset(){
this.queryParams = {
memberName: undefined,
typeId: undefined,
};
this.$refs["form" ].resetFields();
}
},
mounted: function () {
this.init()
}
}
</script>
到此这篇关于ElementUI实现el-form表单重置功能按钮的⽂章就介绍到这了,更多相关Element el-form表单重置内容请搜索以前的⽂章或继续浏览下⾯的相关⽂章希望⼤家以后多多⽀持!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论