VueJS:Error-未定义未捕获的ReferenceError:$



我的Vue代码中有一些问题,我想在Vue中创建一个ScrollToTop按钮,但我在控制台中收到了以下错误消息:

未捕获引用错误:$未定义

我的代码:

export default {
data() {
return {
isExample: false,
}
}
},
mounted() {
window.addEventListener('scroll', this.handleScroll);
},
methods: {
handleScroll() {
if (window.scrollY > 120) {
this.isExample = true,
$('.example-1').addClass("is-close"),
} else if (window.scrollY < 120) {
this.isExample = false,
$('.example-1').removeClass("is-close")
}
}
}
}

尝试在组件中导入jQuery,或在应用程序中全局定义$

import $ from 'jquery'

此外,您可以在js:中执行此操作

document.getElementsByClassName('example-1')

最新更新