【发布时间】:2019-11-03 09:55:01
【问题描述】:
我正在尝试添加一种方法,用于当用户到达窗口底部时,但打字稿阻止了我并说该对象可能在 window.scrollTop()、height() 和 document.height( )。
我已经尝试过预先放置一个 if 语句,并且仅在定义了代码时才运行该代码,但我不断收到错误消息。
mounted() {
// Does not work because object might be undefined
$(window).scroll(() => {
if (
$(window).scrollTop() + $(window).height() >
$(document).height() - 100
) {
console.log(this.lastCursor);
}
});
},
【问题讨论】:
-
所以未定义在窗口上,而不是
this.lastCursor?
标签: jquery typescript vue.js