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