1 回答
TA贡献1829条经验 获得超6个赞
代替:
fetchPartial() {
fetch(this._partial).then(function (response) {
// The API call was successful!
return response.text();
}).then(function (html) {
let elem = document.querySelector( this._target ) // error: TypeError: undefined is not an object (evaluating 'this._target')
elem.innerHTML = html
}).catch(function (err) {
// There was an error
console.warn('Something went wrong.', err);
});
}
你应该做:
fetchPartial() {
fetch(this._partial).then(function (response) {
// The API call was successful!
return response.text();
}).then((html) => {
let elem = document.querySelector( this._target ) // error: TypeError: undefined is not an object (evaluating 'this._target')
elem.innerHTML = html
}).catch(function (err) {
// There was an error
console.warn('Something went wrong.', err);
});
}
使用箭头函数
添加回答
举报