当用户调整窗口大小并达到特定宽度时,我想在div中添加一个类。
这是我的代码
mounted() {
window.addEventListener('resize', this.handleWindowResize);
},
methods: {
handleWindowResize() {
this.windowWidth = event.currentTarget.innerWidth;
},
}
此后我不确定。接下来我该怎么办?
答案 0 :(得分:0)
参见示例:
<script>
export default {
mounted: function () {
window.addEventListener('resize', this.handleResize)
},
methods: {
handleResize () {
let el = document.querySelector('.class-anchor')
if (window.innerWidth < 1024) {
el.classList.add('you-class')
} else {
el.classList.remove('you-class')
}
}
}
}
</script>