天天看點

接口傳回資料的屬性值 不要傳回數字0和1

當屬性有值得時候 判斷屬性是否有值 0的值是false邏輯會錯

const a = {
  b: {
    c: 0
  }
}
if (a) {
  if (a.b) {
    if (a.b.c) { // 這裡是bug c是0 是false 要改成 [undefined, null, ''].includes(a.b.c)
      if (a.b.c === 0) {
        this.text = '否'
      }
      if (a.b.c === 1) {
        this.text = '是'
      }
    }
  }
}