vue.js 操作數據常見報錯 ...split is not a function...


在做數組字符串等接口返回數據操作中經常會遇到這樣的錯誤:vue.js 操作數據常見報錯 ...split is not a function...

而實際運行代碼又可以正常運行並且能夠正常操作數據結果也是對的。那想要去掉這種報錯怎么解決呢:

實際后端返回很多數據看似是字符串,其實是個數組類型。所以只要轉換成字符串即可:

 formatTreeDate(data) {
      if (!data) return;
      var str = data.complainType;
      console.log(typeof str)// obj '1,2' 看着是字符串其實是數組
      str = JSON.stringify(str)
      console.log(typeof str)// str 轉成真正的字符串就不會報錯了
      if (str) {
        str = str.split(",");
        this.form.complainType = str;
      }
      console.log(this.form.complainType);
    },

這種問題常遇到后端接收過來是字符串對象的情況下


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM