Uncaught TypeError: Converting circular structure to JSON


報錯原因

執行JSON.stringify(obj)時 檢測到obj 對象有遞歸引用 (對象的屬性值引用了自身)

// 問題代碼 -- 注意這里有互相引用的問題
this.param = this.contract[this.index]
this.param.list = this.contract

解決方法

賦值時使用 JSON.parse(JSON.stringify()) 來切斷數據之間的相互引用

// 修改后的代碼
this.param = JSON.parse(JSON.stringify(this.contract[this.index]))
this.param.list = JSON.parse(JSON.stringify(this.contract))


免責聲明!

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



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