vue js后台返回值默认为null为0的前端处理方法

export const transObjectValue = (formData) => {  //返回的form表单值为空或为null执行此方法
  Object.keys(formData).forEach((item, index) => {
    if(formData[item] != 0){
      formData[item] = ((formData[item] || '') + '').trim()
    }else if(formData[item] === 0) {
      formData[item] = 0 + '' 
    }else{
      formData[item] = '' 
    }
  })

  return formData
}

 

你可能感兴趣的:(vue,js)