镜花雪月 發表於 2024-2-2 15:37:00

next.js 中引入vconsole,报错 ReferenceError: XMLHttpRequest is not defined

<p>原因好像是服务端渲染没有没有XMLHttpRequest 对象,</p>
<p>解决办法:</p>
<p>_app.tsx中直接引入,不用import</p>
<div class="cnblogs_code">
<pre>&lt;<span style="color: rgba(0, 0, 0, 1)">Script
          src</span>="https://unpkg.com/vconsole@latest/dist/vconsole.min.js"<span style="color: rgba(0, 0, 0, 1)">
          onLoad</span>={() =&gt;<span style="color: rgba(0, 0, 0, 1)"> {
            </span><span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> VConsole();
          }}
      </span>&gt;&lt;/Script&gt;</pre>
</div>
<p>&nbsp;</p><br><br>
来源:https://www.cnblogs.com/fhysy/p/18003291
頁: [1]
查看完整版本: next.js 中引入vconsole,报错 ReferenceError: XMLHttpRequest is not defined