Fetch Error: TypeError: Cannot set property 'info' of undefined

Fetch Error: TypeError: Cannot set property 'info' of undefined
at eval (VM532 HelloWorld.vue:134)

fetch('https://api.coindesk.com/v1/bpi/currentprice.json')
.then(function(response) {
return response.json();
})
.then(function(data) {
console.log('data', data);
this.info=data;

})
.then((data)=>{
this.info=data;
})
.catch(function(error) {
console.log('Fetch Error: ', error);
});

function(data){ } 与(data)=>{} 作用域不一样 ,所以要this.info绑定数据(data)=>{} 写法

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Promise 对象 Promise 的含义 Promise 是异步编程的一种解决方案,比传统的解决方案——回调函...
    neromous阅读 8,731评论 1 56
  • "use strict";function _classCallCheck(e,t){if(!(e instanc...
    久些阅读 2,060评论 0 2
  • 英文文档,一开始我也是抗拒的,边翻译边看,也就花费了1个小时基本就阅读过了,我的英文基础其实很差。附上链接:链接:...
    lonecolonel阅读 10,036评论 3 1
  • # Ajax标签(空格分隔): 笔记整理---[TOC]### 从输入网址开始:- 在学习ajax之前,你应该先了...
    V8阅读 289评论 1 0
  • 先创建服务端的APP 1.官网下载Winrun4j。http://winrun4j.sourceforge.net...
    Alex_1799阅读 1,853评论 1 2