vue使用axios從后台請求數據 根據id進行排序


使用axios 報錯 TypeError: Cannot set property 'listData ' of undefined 

報錯的主要原因是 在 then的內部不能使用vue實例化的this 因為在內部this 因為在內部 this 沒有被綁定

解決辦法:使用ES6箭頭函數,箭頭方法可以和父方法共享變量 ,或者在請求前 定義一下 let _self = this(里面使用到this的替換成_self就好了)

axios .get('https://api.coindesk.com/v1/bpi/currentprice.json') .then(response => { this.listData = response.data.list}) .catch(error => { console.log(error) this.errored = true }) .finally(() => this.loading = false) }

 


免責聲明!

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



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