【发布时间】:2020-12-11 11:38:30
【问题描述】:
我需要观察列表中的元素,并在它们出现在用户视口中时将它们标记为已读。但是当我在数组的开头添加新元素(unshift)时,观察者不起作用:(
我使用 Vue,但我知道问题与它无关。
这是观察者方法,它不会为新元素触发:
onElementObserved(entries) {
entries.forEach(({ target, isIntersecting}) => {
if (!isIntersecting) {
return;
}
this.observer.unobserve(target);
setTimeout(() => {
const i = target.getAttribute("data-index");
this.todos[i].seen = true;
}, 1000)
});
}
【问题讨论】:
标签: vue.js intersection-observer