小编ash*_*rma的帖子

如何在 next.js 中使用 DOMParser?

我想操作一个 html 字符串,在 vanillaJS 中我会这样做:

  let HTMLString = '<p>hello</p>
                            <style> 
                             p{
                               color:black
                              }
                            <p>world</p>
                             '
    const parser = new DOMParser();
    const doc = parser.parseFromString(HTMLString, "text/html");
    doc.querySelectorAll('style').forEach(item => item.remove())
Run Code Online (Sandbox Code Playgroud)

这也适用于反应,但我相信,由于下一步编译服务器端,它只会抛出DOMParser is not defined,我尝试过像这样的包html-react-parser,它们只是将html解析为反应元素,然后提供非常有限的功能,我最后的手段是使用正则表达式,但我认为这不是一个好主意。

任何帮助都会很好,谢谢

javascript dom domparser reactjs next.js

7
推荐指数
1
解决办法
7077
查看次数

Google Cloud Platform 上托管的 nextjs 应用中缺少“_ssgManifest.js”和 _buildManifest.js

有时控制台在打开网站时会显示这些错误

\n
GET https://example.com/subpath/_next/static/9ufj5kFJf/_buildManifest.js\n[HTTP/3 404 Not Found 311ms]\n\nGET https://example.com/subpath/_next/static/9ufj5kFJf/_ssgManifest.js\n[HTTP/3 404 Not Found 334ms]\n\nLoading failed for the <script> with source \xe2\x80\x9chttps://example.com/subpath/_next/static/9ufj5kFJf/_buildManifest.js\xe2\x80\x9d. 1434-247:1:1\nLoading failed for the <script> with source \xe2\x80\x9chttps://example.com/subpath/_next/static/9ufj5kFJf/_ssgManifest.js\xe2\x80\x9d.\n
Run Code Online (Sandbox Code Playgroud)\n

该应用程序确实使用了 ISR,并且似乎有效,它确实得到了更新,这些文件有什么作用?如果他们失踪了会发生什么?

\n
    \n
  • “反应”:“17.0.2”
  • \n
  • “下一个”:“10.1.3”,
  • \n
  • “节点”“15.1.2”
  • \n
\n

javascript reactjs google-cloud-platform gcloud next.js

5
推荐指数
1
解决办法
4785
查看次数