如何在NUXT 3中添加脚本块?
我只想在head
标签中添加脚本
块。
示例
<script>
alert('hello, world!');
</script>
我花了几个小时来找出一个简单的解决方案。 关于添加inline
脚本有很多答案,但是脚本block
nuxt 3
我们如何在nuxt中进行此操作3
?
I simply want to add a script
block in the head
tag.
Example
<script>
alert('hello, world!');
</script>
I spent hours to figure out a solution for something as simple as this.
There are tons of answers about adding inline
scripts, but none for the script block
for Nuxt 3
How can we do this in Nuxt 3
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,我找到了答案。有3种可能的解决方案。
解决方案1
解决方案2
解决方案3
Okay, I found the answer. There are 3 possible solutions.
Solution 1
Solution 2
Solution 3
补充月亮的答案,还有另一种实现这一目标的方法。此方法允许您将其全球导入到应用程序中,并使您可以完全控制标签本身:
解决方案4
此方法还可以与
use> usehead({})
函数一起使用您想将脚本添加到特定页面。Complementing Moon's answer, there is another way to achieve this. This method allows you to import it globally into your app and gives you complete control over the tag itself:
Solution 4
This approach also works with the
useHead({})
function if you want to add a script to a specific page.