1. 程式人生 > 其它 >我藏在你的心裡,你卻不願意尋找# BUG躲貓貓

我藏在你的心裡,你卻不願意尋找# BUG躲貓貓

0. 緣起

涉及到表格賦值初始化,發現有個獲取名字的地方一直報錯,就很納悶。然後一列印,沃日,竟然值都undefined了。

1. 常規方法

當然就是在獲取表格資料前,先把拿到名字陣列的方法做一下。做了,但尼瑪在表格中還是用不了(檸檬樹了)。

再看看this指向有沒有問題,放在函式外面看下有沒有,指向沒有問題,值就是沒有!尼瑪。。。

2. 手牽手,去月球

好吧,這樣我就只好在外面,把它和需要的一起傳進去

    async getMagicBoxInfo(info) {
      await getMagicBoxInfo(info).then((res) => {
        this.tableData = [];
        res.data.records.forEach((key) => {
            // ATTENTION !
          let str = getMagicBoxName(key?.magicBoxType, this.magicBoxArr);
          this.tableData.push({
              // ...
            magicBoxType: str,
          });
        });
        this.totalSize = res.data?.total;
      });
      function getMagicBoxName(type, arr) {
        if (type === null) {
          return "暫無";
        } else {
          let temp = arr.find((key) => {
            return key.code == type;
          });
          return temp !== -1 ? temp.value : "暫無";
        }
      }
    },
人生到處知何似,應似飛鴻踏雪泥。