简体   繁体   English

如何在 NEXTJS 中添加脚本标签?

[英]How to add a script tag in NEXTJS?

I am trying to add sumome to my next application.我正在尝试将 sumome 添加到我的下一个应用程序中。

They provided this code他们提供了这个代码

 <script async>(function(s,u,m,o,j,v){j=u.createElement(m);v=u.getElementsByTagName(m)[0];j.async=1;j.src=o;j.dataset.sumoSiteId='xxxxxxxxxxxxxxxxxxxxxxxxxxx';v.parentNode.insertBefore(j,v)})(window,document,'script','//load.sumo.com/');</script>

I know next has its own script tag but I was unable to set it up correctly using it.我知道 next 有它自己的脚本标签,但我无法使用它正确设置它。 So, I need some help here.所以,我在这里需要一些帮助。 Thank you.谢谢你。

Import Script from next/scriptnext/script导入Script

and use it like this:并像这样使用它:

import Script from 'next/script'

...

<Script
  strategy="afterInteractive"
  dangerouslySetInnerHTML={{
    __html: `
    (function(s,u,m,o,j,v){j=u.createElement(m);v=u.getElementsByTagName(m)[0];j.async=1;j.src=o;j.dataset.sumoSiteId='xxxxxxxxxxxxxxxxxxxxxxxxxxx';v.parentNode.insertBefore(j,v)})(window,document,'script','//load.sumo.com/');
  `,
  }}
/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NextJS API 路由在收到数据之前返回? - NextJS API Route Returns Before Data Received? 在 NextJS 中使用 async 和 Cookies.get 的 useEffect - useEffect with async and Cookies.get in NextJS Cloud firestore和nextjs - getInitialProps和async数据 - Cloud firestore and nextjs - getInitialProps and async data NextJS getServerSideProps() 一次延迟获取多个端点 - NextJS getServerSideProps() fetch multiple endpoints at once in delay NodeJS:如何等待由 runInNewContext 调用的异步脚本? - NodeJS: How to await an asynchronous script called by runInNewContext? 如何在继续执行脚本之前等待 function 的结果? - How to await the result of a function before continuing with the script? 如何将 Telethon 脚本集成到我的事件循环中? - How to intergrate telethon script into my event loop? 如果我在 index.html 的脚本标记中使用异步,我是否需要费心在 scripts.js 中编写异步代码? 我要javascript - If I use async in my script tag in index.html do I need to bother with writing async code in scripts.js? I am asking for javascript 如何顺序执行 java 脚本代码? - How to execute the java script code sequentially? NextJs - 节点 - API 在不发送 /api/xxx 响应的情况下解析 - NextJs - Node - API resolved without sending a response for /api/xxx
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM