我只想在script
标记中添加一个head
块。
示例
<script>
alert('hello, world!');
</script>
我花了几个小时想出这样简单的解决方案。关于添加inline
脚本有很多答案,但是对于脚本block
for Nuxt 3
没有答案。
我们如何在Nuxt 3
中做到这一点?
发布于 2022-07-03 19:24:17
好吧,我找到答案了。有三种可能的解决方案。
解决方案1
<template>
<Script children="console.log('Hello, world!');" />
</template>
解决方案2
<script setup>
useHead({
script: [{ children: "console.log('Hello, world!');" }],
});
</script>
解决方案3
import { defineNuxtConfig } from 'nuxt';
export default defineNuxtConfig({
app: {
head: {
script: [{ children: "console.log('Hello, world!');" }],
},
},
});
https://stackoverflow.com/questions/72848779
复制相似问题