<template>
el-form :model="ruleForm"
:rules="rules"
ref
label-width="100px"
class="demo-ruleForm">
el-form-item label="姓名"
prop="username">
el-input v-model="ruleForm.username"></el-input</el-form-item="年龄"="age"="ruleForm.age"="性别"="gender"el-radio-group ="ruleForm.gender">
el-radio ="0"el-radio="1"el-radio-group="邮箱"="email"="ruleForm.email"="爱好"="hobby"="ruleForm.hobby"="介绍"="introduce"type="textarea"
v-model="ruleForm.introduce"el-button ="primary"
@click="submitForm('ruleForm')">立即创建el-button@click="resetForm('ruleForm')">重置el-form>
>
script>
export default {
data () {
return {
ruleForm: {
username: '',age: '',gender: '',email: '',hobby: '',introduction: ''
},rules: {
username: [
{ required: true,message: '请输入姓名',trigger: 'blur' },{ min: 3,max: 5,message: '长度在 3 到 5 个字符',trigger: 'blur' }
],}
};
},methods: {
submitForm (formName) {
const that = this;
this.$refs[formName].validate((valid) => {
if (valid) {
axios.post('http://localhost:8181/user/save',this.ruleForm)
.then(function (response) {
if (response.data == "success") {
that.$alert('《' + that.ruleForm.username + '》 添加成功','消息',{
confirmButtonText: '确定',callback: action => {
that.$router.push('/pageOne');
}
})
}
})
} else {
console.log('error submit!!');
return false;
}
});
},resetForm (formName) {
this.$refs[formName].resetFields();
}
}
}
>
@ResponseBody
@PostMapping("/save")
public String save(@RequestBody User user){
userRepository.save(user);
return "success";
}