在开发nuxt项目的时候,我们难免会使用到document来获取dom元素。如果直接在文件中使用就会报错。这是因为document是浏览器端的东西服务端并没有。
解决方法:
我们只需要在使用的地方通过process.browser/process.server来判断
如下:
if (process.browser) { let myVideo = document.getElementById('mini_video'); if (myVideo) { if (!this.videoShow) { myVideo.pause(); } else { myVideo.play(); } } }