我必须在<head>标签中添加以下脚本。但在 Nuxt 中,我必须将其作为 objext 添加到 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>
Run Code Online (Sandbox Code Playgroud)
2种方法
head()第一:在 nuxt-page-component 中使用 nuxt (推荐)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);`
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
在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);`
}
]
}
};
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6903 次 |
| 最近记录: |