element关闭弹窗清除表单验证的方法
element
A Vue.js 2.0 UI Toolkit for Web
项目地址:https://gitcode.com/gh_mirrors/eleme/element

·
<template>
<div>
<el-dialog
:title="title"
:visible.sync="dialogVisible"
width="30%"
@closed="handleClose">
<el-form
:model="ruleForm"
ref="ruleForm"
label-width="100px"
class="demo-ruleForm"
:rules="rules">
<el-form-item label="用户编号" prop="id">
<el-input v-model="ruleForm.id" :maxlength="5" :disabled="true"></el-input>
</el-form-item>
<el-form-item label="用户性别" prop="sex">
<el-radio-group v-model="ruleForm.sex">
<el-radio :label="1">男</el-radio>
<el-radio :label="0">女</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="用户备注" prop="count">
<el-input v-model="ruleForm.count" :maxlength="10"></el-input>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false">取 消</el-button>
<el-button
type="primary"
@click="handleSubmit">
确 定
</el-button>
</span>
</el-dialog>
</div>
</template>
<script>
export default {
model: {
prop: 'ruleForm',
event: 'change'
},
props: {
ruleForm: {
type: Object,
default () {
return {
id: '',
sex: 0,
count: ''
}
}
},
title: {
type: String,
default: ''
}
},
data () {
return {
dialogVisible: false,
rules: {
id: [
{ required: true, message: '请输入用户编号', trigger: 'change' }
],
sex: [
{ required: true, message: '请选择用户性别', trigger: 'change' }
],
count: [
{ required: true, message: '请输入用户统计', trigger: 'change' }
]
}
}
},
methods: {
show () {
this.dialogVisible = true
},
handleClose () {
this.$refs.ruleForm.resetFields()
this.$emit('handleClose')
},
handleSubmit () {
this.$refs.ruleForm.validate((valid) => {
if (valid) {
this.$emit('handleSubmit')
this.dialogVisible = false
} else {
this.$message.error('输入信息有误,请重新输入!')
}
})
}
}
}
</script>
关闭的时候清除表单数据
handleClose () {
this.ruleForm = {
id: '',
sex: 1,
count: ''
}
}




A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:19 天前 )
c345bb45
1 年前
a07f3a59
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update table.md
* Update transition.md
* Update popover.md 1 年前
更多推荐
所有评论(0)