Element UI在dialog对话框中嵌套form表单的使用
element
A Vue.js 2.0 UI Toolkit for Web
项目地址:https://gitcode.com/gh_mirrors/eleme/element
·
Element UI在dialog对话框中嵌套form表单的使用
html部分
<el-button type="primary" @click="adduser">添加用户</el-button>
<el-dialog title="添加用户" :visible.sync="dialogFormVisible">
<el-form
:model="userForm"
ref="userForm"
:rules="rules"
label-position="left"
>
<el-form-item label="用户名称" prop="name">
<el-input v-model="userForm.name"></el-input>
</el-form-item>
<el-form-item label="用户电话" prop="tel">
<el-input v-model="userForm.tel"></el-input>
</el-form-item>
<el-form-item label="用户性别" prop="sex">
<template>
<el-select
v-model="userForm.sex"
clearable
placeholder="请选择性别"
>
<el-option
v-for="item in options"
:key="item.value"
:label="item.label"
:value="item.value"
>
</el-option>
</el-select>
</template>
</el-form-item>
<el-form-item label="用户简介" prop="introduction">
<el-input v-model="userForm.introduction"></el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="cancel">取 消</el-button>
<el-button type="primary" @click="confirmAddUser(userForm)"
>确 定</el-button
>
</div>
</el-dialog>
js部分
data() {
return {
userForm: {},
dialogFormVisible: false,
rules: { //表单验证
name: [{ required: true, message: "请输入用户名称", trigger: "blur" }],
tel: [{ required: true, message: "请输入用户电话", trigger: "blur" }],
sex: [{ required: true, message: "请选择用户性别", trigger: "blur" }],
introduction: [
{ required: true, message: "请输入用户简介", trigger: "blur" }
]
},
options: [ //下拉框选项
{
value: "1",
label: "男"
},
{
value: "2",
label: "女"
}
]
};
},
methods:{
adduser() {
this.dialogFormVisible = true;
},
confirmAddUser(form) {
this.$refs.userForm.validate(valid => {
if (valid) { //表单验证通过
console.log(form); //form就是form表单对象
this.loading = true;
this.$http
.post("http://127.0.0.1:8888/user/create", { data: form })
.then(res => {
// console.log(res);
this.loading = false;
this.dialogFormVisible = false;
this.getList();//重新调用渲染列表的方法
this.$message({ message: "添加成功", type: "success" });
});
} else {
console.log("error submit!!");
return false;
}
});
}
}
A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:2 个月前 )
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 年前
新一代开源开发者平台 GitCode,通过集成代码托管服务、代码仓库以及可信赖的开源组件库,让开发者可以在云端进行代码托管和开发。旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。
更多推荐

所有评论(0)