usePage增加许多配置项,另外增加一些回调函数、插槽等等,修改逻辑增强配置灵活性
zk authored at 2023-11-21 17:42:23
693.00 B
NewLife.QuickVue
import { FormInstance } from "element-plus";
import { computed, ref } from "vue";
import { FormEmits, FormProps } from "../model/form";

export default function useForm (props: FormProps, emits: FormEmits) {
  const formEl = ref<FormInstance>();
  const formValue = computed({
    get () {
      return props.modelValue;
    },
    set (val) {
      emits('update:modelValue', val);
    }
  });
  const onChange = (...props: any[]) => {
    emits('change', ...props);
  }
  const getColBind = (col?: number | Col) => {
    if (typeof col === 'number') {
      return {
        span: col
      }
    }
    return col
  }
  return {
    formEl,
    formValue,
    onChange,
    getColBind,
  }
}