设计一个vue3的el-form-item两列四行的布局
时间: 2023-12-14 07:13:52 浏览: 156
Vue中el-form标签中的自定义el-select下拉框标签功能
可以使用`ElRow`和`ElCol`组件来实现两列四行的布局,每行包含两个`ElFormItem`组件。
示例代码如下:
```vue
<template>
<el-form>
<el-row>
<el-col :span="12">
<el-form-item label="姓名" prop="name">
<el-input v-model="form.name"></el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="年龄" prop="age">
<el-input v-model="form.age"></el-input>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
<el-form-item label="性别" prop="gender">
<el-radio-group v-model="form.gender">
<el-radio label="male">男</el-radio>
<el-radio label="female">女</el-radio>
</el-radio-group>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="职业" prop="job">
<el-select v-model="form.job" placeholder="请选择">
<el-option label="工程师" value="engineer"></el-option>
<el-option label="教师" value="teacher"></el-option>
<el-option label="医生" value="doctor"></el-option>
</el-select>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
<el-form-item label="手机号码" prop="phone">
<el-input v-model="form.phone"></el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="邮箱" prop="email">
<el-input v-model="form.email"></el-input>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="24">
<el-form-item>
<el-button type="primary" @click="submitForm">提交</el-button>
</el-form-item>
</el-col>
</el-row>
</el-form>
</template>
<script>
export default {
data() {
return {
form: {
name: '',
age: '',
gender: '',
job: '',
phone: '',
email: ''
}
};
},
methods: {
submitForm() {
this.$refs.form.validate(valid => {
if (valid) {
console.log('submit form');
} else {
console.log('validation failed');
return false;
}
});
}
}
};
</script>
```
效果如下:
![el-form-item两列四行的布局](https://img-blog.csdnimg.cn/2021110319480992.png)
阅读全文