<template>
  <div class="com-one">
    <h1>我是ComOne组件</h1>
    <el-button type="primary">主要按钮</el-button>
    <el-button type="primary" icon="el-icon-edit" circle></el-button>
    <i class="el-icon-upload"></i>
    <div class="box">
    <el-form
      :model="numberValidateForm"
      ref="numberValidateForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item
        label="年龄"
        prop="age"
        :rules="[
          { required: true, message: '年龄不能为空' },
          { type: 'number', message: '年龄必须为数字值' },
        ]"
      >
        <el-input
          type="age"
          v-model.number="numberValidateForm.age"
          autocomplete="off"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('numberValidateForm')"
          >提交</el-button
        >
        <el-button @click="resetForm('numberValidateForm')">重置</el-button>
      </el-form-item>
    </el-form>
    </div>
  </div>
</template>
<script>
export default {
  name: "ComOne",
  data() {
    return {
      numberValidateForm: {
        age: 10,
      },
    };
  },
  methods: {
    submitForm(formName) {
        // 校验表单 validate 校验表单是否通过
      this.$refs[formName].validate((valid) => {
        // 校验通过 valid 则为true
        if (valid) {
          alert("submit!");
        } else {
            // 校验不通过 valid 则false
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>
<style scoped>
.box{
    width: 400px;
    margin: 100px auto;
    text-align: left;
}
</style>