vxe-form table 表單使用資料校驗

可不简单發表於2024-11-25

官網:https://vxeui.com

<template>
  <div>
    <vxe-form
      v-bind="formOptions"
      @submit="submitEvent"
      @reset="resetEvent">
    </vxe-form>
  </div>
</template>

<script>
import { VxeUI } from 'vxe-pc-ui'

export default {
  data () {
    const formOptions = {
      validConfig: {
        theme: 'beautify'
      },
      data: {
        name: '',
        nickname: '',
        sex: '',
        age: ''
      },
      rules: {
        name: [
          { required: true, message: '請輸入名稱' }
        ],
        sex: [
          { required: true, message: '請選擇性別' }
        ],
        age: [
          { required: true, message: '請輸入年齡' }
        ]
      },
      items: [
        { field: 'name', title: '名稱', span: 24, itemRender: { name: 'VxeInput' } },
        { field: 'sex', title: '性別', span: 12, itemRender: { name: 'VxeInput' } },
        { field: 'age', title: '年齡', span: 12, itemRender: { name: 'VxeInput' } },
        {
          align: 'center',
          span: 24,
          itemRender: {
            name: 'VxeButtonGroup',
            options: [
              { type: 'submit', content: '提交', status: 'primary' },
              { type: 'reset', content: '重置' }
            ]
          }
        }
      ]
    }
    return {
      formOptions
    }
  },
  methods: {
    submitEvent () {
      VxeUI.modal.message({ content: '儲存成功', status: 'success' })
    },
    resetEvent () {
      VxeUI.modal.message({ content: '重置事件', status: 'info' })
    }
  }
}
</script>

https://gitee.com/x-extends/vxe-pc-ui

相關文章