Appearance
组件方法
DrForm 方法
通过 ref 调用表单方法:
vue
<template>
<DrForm ref="formRef" :fieldList="fieldList" />
<el-button @click="validate">验证</el-button>
</template>
<script setup>
import { ref } from 'vue'
const formRef = ref()
const validate = async () => {
try {
await formRef.value.validate()
console.log('验证通过')
} catch (e) {
console.log('验证失败')
}
}
</script>validate
验证整个表单。
ts
async validate(): Promise<boolean>返回值:
- 验证通过:resolve
true - 验证失败:reject
validateField
验证指定字段。
ts
validateField(props: string[], callback?: Function): void参数:
props- 字段名数组callback- 回调函数
clearValidate
清除验证信息。
ts
clearValidate(props?: string[]): void参数:
props- 字段名数组,不传则清除所有
validateUpload
验证上传中的文件。
ts
async validateUpload(): Promise<boolean>返回值:
- 所有上传完成:resolve
true - 有上传中:resolve
false
DrSearchForm 方法
reset
重置搜索条件。
ts
reset(): voidexpand
切换展开/收起。
ts
expand(): voidDrTable 方法
clearSelection
清除选择。
ts
clearSelection(): voidtoggleRowSelection
切换行选择。
ts
toggleRowSelection(row: any, selected?: boolean): voidtoggleAllSelection
切换全选。
ts
toggleAllSelection(): voidsetCurrentRow
设置当前行。
ts
setCurrentRow(row: any): voidclearSort
清除排序。
ts
clearSort(): voidclearFilter
清除筛选。
ts
clearFilter(columnKey?: string): voiddoLayout
重新布局。
ts
doLayout(): voidsort
手动排序。
ts
sort(prop: string, order: 'ascending' | 'descending'): void