手写 el-form el-form-item
时间: 2023-10-14 20:05:07 浏览: 118
手动动态改变el-tabs标签页顺序
<>
<el-form ref="myForm" :model="form" label-width="120px">
<el-form-item label="姓名" prop="name">
<el-input v-model="form.name"></el-input>
</el-form-item>
<el-form-item label="年龄" prop="age">
<el-input v-model="form.age"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="submitForm">提交</el-button>
</el-form-item>
</el-form>
</template>
<script>
export default {
data() {
return {
form: {
name: '',
age: ''
}
};
},
methods: {
submitForm() {
this.$refs.myForm.validate((valid) => {
if (valid) {
// 在这里处理表单提交逻辑
console.log(this.form);
} else {
console.log('表单校验失败');
return false;
}
});
}
}
};
</script>
阅读全文