我有点问题。我有一些数据和一些方法可以处理这些数据。但是当我想要更改属性固定时,我会收到错误。
export default {
data() {
return {
classes: {
titleSection: "title-section",
fixed: false
},
}
},
methods: {
handleScroll() {
let coordsSection1 = this.getCoords(document.getElementById('section-1'));
if (window.pageYOffset > coordsSection1) {
this.classes.fixed = "fixed"; //this line get error
}
console.log(this.classes.fixed);
},
getCoords(elem) {
let box = elem.getBoundingClientRect();
return {
top: box.top + pageYOffset,
left: box.left + pageXOffset
}
}
},
created() {
window.addEventListener('scroll', this.handleScroll);
},
destroyed() {
window.removeEventListener('scroll', this.handleScroll);
}
}