這里是引用
function (res) {} 中 打印this時是undefined 打印that時是有內容的
let that = this;
getTotal().then(function (res) {
console.log(this);
console.log(that);
this.totalData = res.body.content;
this.total = res.body.total;
})
結果
(res) =>{}中打印 this 和 that 都是有內容的
let that = this;
getTotal().then((res) =>{
console.log(this);
console.log(that)
this.totalData = res.body.content;
this.total = res.body.total;
})
結果
原文鏈接:https://blog.csdn.net/qq_40121328/article/details/108828755