How promise returns a value instead of promise

function _getProductType (arr, num, str) {
  let type = ""
  arr.forEach(val => {
    if (num == val.code_val) { //eslint-disable-line
      type = val.code_desc
    } else if (num == "1000") { //eslint-disable-line
      type = ""
    }
  })
  return type + "" + (str || "")
}
export async function productType (num, str) {
  let productTypes = []
  function aaa () {
    return getByCode(52).then(res => {
      if (res.data.success) {
        productTypes = res.data.data
        return _getProductType(productTypes, num, str)
      }
    })
  }
  let b = await aaa()
  return b
}

productType is a filter for vue, but returns promise, but the label attribute in template accepts only string types.
how to deal with this situation (axios is also owned by promise.)

clipboard.png

Jan.02,2022

export async function productType (num, str) {
  const res = await getByCode(52);
  if (res.data.success) {
    let productTypes = res.data.data;
    return _getProductType(productTypes, num, str)
  }
  return 'ERROR' //?
}

written by guessing, your aaa function is completely redundant from the code. If you can't run it, change your own thinking

.

ide/filters.html" rel=" nofollow noreferrer "> filters can only be a Synchronize function.

Menu