nextjs项目引入vconsole报错处理:ReferenceError: window is not defined
引入文件(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()
}
}
有问题欢迎交流,谢谢!

浙公网安备 33010602011771号