在此代码片段中,我使用事件侦听器。构建时,会产生错误“未定义窗口”。你能告诉我如何解决这个问题吗?NUXTJS!
methods: {
onResize() {
this.onMobileCondition = window.innerWidth <= 600;
}
},
created() {
window.addEventListener("resize", this.onResize);
this.onResize();
},
destroyed() {
window.removeEventListener("resize", this.onResize);
}
尝试将所有写在里面
created()
和. nuxt 文档:https ://nuxtjs.org/faq/window-document-undefined/destroyed()
if (process.browser) { }