type

string: 必须是字符串类型。这是默认类型
number: 必须是数字
boolean: 必须是布尔型的
method:必须是类型函数
regexp: 必须是ReGEXP的实例,或者是在创建新的ReGEXP时不会生成异常的字符串
integer:必须是整数.
float:必须是浮点数.
array: 必须是由Array.isArray确定的数组
object: 必须是类型对象而不是Array.isArray
enum: 枚举中必须存在值。
date: 按日期确定的值必须有效
url: 必须是URL类型。
hex: 必须是十六进制。
email:必须是电子邮件类型。
required:true | false
pattern :正则表达式
min: 最小值
max: 最大值
Length : 长度
enum: 验证字段是否存在其中
messages: 错误信息
trigger : ‘change’ | ‘blur’
whitespace : true | false
true:空白字符 ->错误提醒
false: 空白字符->不报错

  1. <Form
  2. ref="formModel"
  3. :model="addLeaseOrderForm"
  4. label-position="top"
  5. :rules="ruleValidate">
  6. <FormItem :label="$t('keyless_customer.add_order_user')" prop="user_name">
  7. <!-- <Input class="user-textarea"
  8. type="textarea"
  9. v-model="addLeaseOrderForm.user_name"
  10. :rows="6"
  11. :placeholder="$t('batteryManage.text_pls_input')">
  12. </Input> -->
  13. <input-tag
  14. class="user-textarea"
  15. v-model="addLeaseOrderForm.user_name">
  16. </input-tag>
  17. </FormItem>
  18. <FormItem :label="$t('keyless_customer.add_order_car')" prop="devices">
  19. <Row style="margin-bottom: 30px;">
  20. <div class="add-devices-button" @click="openAddDevice">
  21. <Icon type="md-add" />
  22. <span>{{$t('keyless_customer.give_title')}}</span>
  23. </div>
  24. </Row>
  25. <Row>
  26. <Table class="add-devices-detail" :columns="currentColumns" :data="formatData">
  27. <template slot-scope="{ row, index }" slot="add_order_table_name">
  28. <span class="tableProminentStyle">{{ row.add_order_table_name }}</span>
  29. </template>
  30. <template slot-scope="{ row, index }" slot="add_order_table_car_id">
  31. <span class="tableProminentStyle">{{ row.add_order_table_car_id }}</span>
  32. </template>
  33. <template slot-scope="{ row, index }" slot="sn">
  34. <span class="tableProminentStyle">{{ row.sn }}</span>
  35. </template>
  36. <template slot-scope="{ row, index }" slot="vin">
  37. <span class="tableProminentStyle">{{ row.vin }}</span>
  38. </template>
  39. <template slot-scope="{ row, index }" slot="action">
  40. <span class="tableFontStyle" @click="cancelAction(row)">取消</span>
  41. </template>
  42. </Table>
  43. <!-- 页码 -->
  44. <div class="page">
  45. <Page
  46. show-sizer
  47. :total="totalPage"
  48. :current.sync="currentPage"
  49. :page-size-opts="selectPageSize"
  50. @on-change="changeListPage"
  51. @on-page-size-change="changePageSize">
  52. </Page>
  53. </div>
  54. </Row>
  55. </FormItem>
  56. <Row :gutter="34">
  57. <Col :sm='12' :xs='24'>
  58. <FormItem :label="$t('keyless_customer.start_time')" prop="start_time">
  59. <DatePicker
  60. style="width: 100%;"
  61. v-model="addLeaseOrderForm.start_time"
  62. type="datetime"
  63. format="yyyy.MM.dd HH:mm"
  64. placeholder="Select date">
  65. </DatePicker>
  66. </FormItem>
  67. </Col>
  68. <Col :sm='12' :xs='24'>
  69. <FormItem :label="$t('keyless_customer.end_time')" prop="end_time">
  70. <DatePicker
  71. style="width: 100%;"
  72. v-model="addLeaseOrderForm.end_time"
  73. type="datetime"
  74. format="yyyy.MM.dd HH:mm"
  75. placeholder="Select date">
  76. </DatePicker>
  77. </FormItem>
  78. </Col>
  79. </Row>
  80. <FormItem :label="$t('keyless_customer.add_order_revert')" prop="revert">
  81. <RadioGroup v-model="addLeaseOrderForm.revert">
  82. <Radio label="yes" style="margin-right: 40px;">
  83. <span>{{$t('keyless_customer.add_order_open_revert')}}</span>
  84. </Radio>
  85. <Radio label="no">
  86. <span>{{$t('keyless_customer.add_order_unopen_revert')}}</span>
  87. </Radio>
  88. </RadioGroup>
  89. </FormItem>
  90. <Row>
  91. <base-button :value="$t('keyless_customer.submit')" :buttonHandleClick='handleSubmit'></base-button>
  92. </Row>
  93. </Form>
  94. addLeaseOrderForm: {
  95. user_name: [],
  96. devices: [],
  97. start_time: '',
  98. end_time: '',
  99. revert: null,
  100. },
  101. ruleValidate: {
  102. user_name: [{
  103. required: true,
  104. type: 'array',
  105. message: this.$t('rule.required'),
  106. trigger: "submit"
  107. }],
  108. devices: [{
  109. required: true,
  110. type: 'array',
  111. message: this.$t('rule.required'),
  112. trigger: 'submit'
  113. }],
  114. start_time: [{
  115. required: true,
  116. type: 'date',
  117. message: this.$t('rule.required'),
  118. trigger: 'submit'
  119. }],
  120. end_time: [{
  121. required: true,
  122. type: 'date',
  123. message: this.$t('rule.required'),
  124. trigger: 'submit'
  125. }],
  126. revert: [{
  127. required: true,
  128. type: 'string',
  129. message: this.$t('rule.required'),
  130. trigger: 'submit'
  131. }],
  132. },
  133. handleSubmit() {
  134. this.$refs.formModel.validate(valid => {
  135. if (valid) {
  136. };
  137. });
  138. }

参考

  1. Iview 表单验证的规则总结