Blame view

examples/routers/form.vue 2.04 KB
9f5e2c7e   梁灏   update Form
1
  <template>
21dad188   梁灏   prevent dispatch ...
2
3
4
5
6
7
8
9
10
11
12
13
14
15
      <div>
          date: {{ formInline.date }}
          <i-form ref="formInline" :model="formInline" :rules="ruleInline">
              <Form-item prop="date">
                  <Date-picker type="date" placeholder="选择日期" v-model="formInline.date"></Date-picker>
              </Form-item>
              <Form-item prop="user">
                  <Input v-model="formInline.user">
              </Form-item>
              <Form-item>
                  <i-button type="primary" @click.native="handleSubmit('formInline')">登录</i-button>
              </Form-item>
          </i-form>
      </div>
9f5e2c7e   梁灏   update Form
16
17
18
  </template>
  <script>
      export default {
9f5e2c7e   梁灏   update Form
19
          data () {
184dba1c   梁灏   update Form
20
              return {
257f80f1   梁灏   support Form
21
                  formInline: {
21dad188   梁灏   prevent dispatch ...
22
23
                      date: new Date(),
                      user: ''
c3a9f389   梁灏   update Input
24
                  },
257f80f1   梁灏   support Form
25
                  ruleInline: {
21dad188   梁灏   prevent dispatch ...
26
27
28
29
30
31
32
                      date: [
                          {
                              required: true,
                              type: 'date',
                              message: '请选择日期',
                              trigger: 'change'
                          }
257f80f1   梁灏   support Form
33
                      ],
21dad188   梁灏   prevent dispatch ...
34
35
36
37
38
39
40
41
42
43
44
45
                      user: [
                          {
                              required: true,
                              message: '请输入',
                              trigger: 'change',
                              min: 10
                          },
                          {
                              required: true,
                              message: '请输入2',
                              trigger: 'blur'
                          }
257f80f1   梁灏   support Form
46
                      ]
184dba1c   梁灏   update Form
47
48
                  }
              }
9f5e2c7e   梁灏   update Form
49
          },
184dba1c   梁灏   update Form
50
          methods: {
257f80f1   梁灏   support Form
51
              handleSubmit(name) {
c3a9f389   梁灏   update Input
52
53
                  this.$refs[name].validate((valid) => {
                      if (valid) {
21dad188   梁灏   prevent dispatch ...
54
                          this.$Message.success('提交成功!');
c3a9f389   梁灏   update Input
55
                      } else {
21dad188   梁灏   prevent dispatch ...
56
                          this.$Message.error('表单验证失败!');
c3a9f389   梁灏   update Input
57
58
                      }
                  })
21dad188   梁灏   prevent dispatch ...
59
60
61
              },
              handleInput (val) {
                  console.log(val)
184dba1c   梁灏   update Form
62
63
              }
          }
8bca1070   梁灏   update Input on-f...
64
65
      }
  </script>