不想在iview表单校验回调函数里写逻辑?试试Promisify吧

 

const valid = await promisify(myForm.validate, myForm)()
if (!valid) {
      this.$Message.warning('Please Complete the Form!')
      return
}
/**
 * 方法回调promise化
 */
export const promisify = (fn: any, receiver?: any) => {
  return (...args: any) => {
    return new Promise((resolve) => {
      fn.apply(receiver, [
        ...args,
        (res: any) => {
          return resolve(res)
        }
      ])
    })
  }
}

 

你可能感兴趣的:(JavaScript)