使用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) }