ComOne.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <template>
  2. <div class="com-one">
  3. <h1>我是ComOne组件</h1>
  4. <el-button type="primary">主要按钮</el-button>
  5. <el-button type="primary" icon="el-icon-edit" circle></el-button>
  6. <i class="el-icon-upload"></i>
  7. <div class="box">
  8. <el-form
  9. :model="numberValidateForm"
  10. ref="numberValidateForm"
  11. label-width="100px"
  12. class="demo-ruleForm"
  13. >
  14. <el-form-item
  15. label="年龄"
  16. prop="age"
  17. :rules="[
  18. { required: true, message: '年龄不能为空' },
  19. { type: 'number', message: '年龄必须为数字值' },
  20. ]"
  21. >
  22. <el-input
  23. type="age"
  24. v-model.number="numberValidateForm.age"
  25. autocomplete="off"
  26. ></el-input>
  27. </el-form-item>
  28. <el-form-item>
  29. <el-button type="primary" @click="submitForm('numberValidateForm')"
  30. >提交</el-button
  31. >
  32. <el-button @click="resetForm('numberValidateForm')">重置</el-button>
  33. </el-form-item>
  34. </el-form>
  35. </div>
  36. </div>
  37. </template>
  38. <script>
  39. export default {
  40. name: "ComOne",
  41. data() {
  42. return {
  43. numberValidateForm: {
  44. age: 10,
  45. },
  46. };
  47. },
  48. methods: {
  49. submitForm(formName) {
  50. // 校验表单 validate 校验表单是否通过
  51. this.$refs[formName].validate((valid) => {
  52. // 校验通过 valid 则为true
  53. if (valid) {
  54. alert("submit!");
  55. } else {
  56. // 校验不通过 valid 则false
  57. console.log("error submit!!");
  58. return false;
  59. }
  60. });
  61. },
  62. resetForm(formName) {
  63. this.$refs[formName].resetFields();
  64. },
  65. },
  66. };
  67. </script>
  68. <style scoped>
  69. .box{
  70. width: 400px;
  71. margin: 100px auto;
  72. text-align: left;
  73. }
  74. </style>