首页 > 其他分享 >nextjs项目引入vconsole报错处理:ReferenceError: window is not defined

nextjs项目引入vconsole报错处理:ReferenceError: window is not defined

时间:2023-06-28 15:48:12浏览次数:35  
标签:Vconsole defined vconsole window 报错 nextjs

引入文件(nextjs项目):

import Vconsole from 'vconsole'

  

报错:

 

处理:

let Vconsole

if (typeof window !== 'undefined') {
  Vconsole = require('vconsole')
}

  

打开调试:

if (typeof window !== 'undefined') {
// 加了一个打开调试的条件 const debugConfig = /debug=1/g.test(location.href) if (debugConfig) { new Vconsole() } }

  

有问题欢迎交流,谢谢!

     

标签:Vconsole,defined,vconsole,window,报错,nextjs
From: https://www.cnblogs.com/mihoutaoguniang/p/17511521.html

相关文章