我正在调用一个给我一个JSON数组的API,所以我想将返回的数据分配给LANDMARKS
变量。
源代码:
export const LANDMARKS : Landmark[] = this.myobj;
console.log(this.myItems);
fetch('https://jsonplaceholder.typicode.com/users')
.then(response => response.json())
.then(json => {this.myItems = json;
console.log(this.myItems);
**const myobj = this.myItems**
// return myobj;
}
);
答案 0 :(得分:0)
尝试以下代码:
export const LANDMARKS: Landmark[] = [];
fetch('https://jsonplaceholder.typicode.com/users')
.then(response => response.json())
.then(json => {
var myItems = json;
this.LANDMARKS = myItems;
console.log('--Landmark List--',this.LANDMARKS);
});