-6ren"> -我必须在 中添加以下脚本标签。但是在 Nuxt 中,我必须将它作为对象添加到 nuxt.config.js 中。 我该怎么做? /* To enable Participant Auto Au-6ren">
gpt4 book ai didi

nuxt.js - 如何在Nuxt中添加 "text/javascript"到

转载 作者:行者123 更新时间:2023-12-02 18:59:51 25 4
gpt4 key购买 nike

我必须在 <head> 中添加以下脚本标签。但是在 Nuxt 中,我必须将它作为对象添加到 nuxt.config.js 中。

我该怎么做?

<script type="text/javascript">
/* To enable Participant Auto Authentication, uncomment this code below (https://docs.growsurf.com/getting-started/participant-auto-authentication) */
/*
window.grsfConfig = {
email: "participant@email.com",// Replace this with the participant's email address
hash: "HASH_VALUE" // Replace this with the SHA-256 HMAC value
};
*/
(function(g,r,s,f){g.grsfSettings={campaignId:"mpw47p",version:"2.0.0"};s=r.getElementsByTagName("head")[0];f=r.createElement("script");f.async=1;f.src="https://app.growsurf.com/growsurf.js"+"?v="+g.grsfSettings.version;f.setAttribute("grsf-campaign", g.grsfSettings.campaignId);!g.grsfInit?s.appendChild(f):"";})(window,document);
</script>

最佳答案

2 种方法

  1. 首先:在nuxt-page-component中使用nuxt head()(推荐)
export default{
head(){
return {
script: [
{
type:'text/javascript',
innerHTML: `/* To enable Participant Auto Authentication, uncomment this code below (https://docs.growsurf.com/getting-started/participant-auto-authentication) */
/*
window.grsfConfig = {
email: "participant@email.com",// Replace this with the participant's email address
hash: "HASH_VALUE" // Replace this with the SHA-256 HMAC value
};
*/
(function(g,r,s,f){g.grsfSettings={campaignId:"mpw47p",version:"2.0.0"};s=r.getElementsByTagName("head")[0];f=r.createElement("script");f.async=1;f.src="https://app.growsurf.com/growsurf.js"+"?v="+g.grsfSettings.version;f.setAttribute("grsf-campaign", g.grsfSettings.campaignId);!g.grsfInit?s.appendChild(f):"";})(window,document);`
}
]
}
}
}

nuxt.config.js 中:

module.exports = {
head: {
script: [
{
type:'text/javascript',
innerHTML: `/* To enable Participant Auto Authentication, uncomment this code below (https://docs.growsurf.com/getting-started/participant-auto-authentication) */
/*
window.grsfConfig = {
email: "participant@email.com",// Replace this with the participant's email address
hash: "HASH_VALUE" // Replace this with the SHA-256 HMAC value
};
*/
(function(g,r,s,f){g.grsfSettings={campaignId:"mpw47p",version:"2.0.0"};s=r.getElementsByTagName("head")[0];f=r.createElement("script");f.async=1;f.src="https://app.growsurf.com/growsurf.js"+"?v="+g.grsfSettings.version;f.setAttribute("grsf-campaign", g.grsfSettings.campaignId);!g.grsfInit?s.appendChild(f):"";})(window,document);`
}
]
}
};

这就是你得到的 enter image description here

  1. 第二个:自定义index.html
<!DOCTYPE html>
<html {{ HTML_ATTRS }}>
<head {{ HEAD_ATTRS }}>
{{ HEAD }}
<script type="text/javascript">
/* To enable Participant Auto Authentication, uncomment this code below (https://docs.growsurf.com/getting-started/participant-auto-authentication) */
/*
window.grsfConfig = {
email: "participant@email.com",// Replace this with the participant's email address
hash: "HASH_VALUE" // Replace this with the SHA-256 HMAC value
};
*/
(function(g,r,s,f){g.grsfSettings={campaignId:"mpw47p",version:"2.0.0"};s=r.getElementsByTagName("head")[0];f=r.createElement("script");f.async=1;f.src="https://app.growsurf.com/growsurf.js"+"?v="+g.grsfSettings.version;f.setAttribute("grsf-campaign", g.grsfSettings.campaignId);!g.grsfInit?s.appendChild(f):"";})(window,document);
</script>
</head>
<body {{ BODY_ATTRS }}>
{{ APP }}
</body>
</html>

关于nuxt.js - 如何在Nuxt中添加 "text/javascript"到<head>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65713431/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com