🖥

Nuxt 3 / Vue 3 - 外部 jabascript ファイル ( src ) を設定する例

に公開

問題

template に script タグが書けない

<template>
  <html>
    <head>
      <script src="example.js"></script>
    </head>
  </html>
</template>

以下エラーが発生する

Tags with side effect (<script> and <style>) are ignored in client component templates.

対策

useHead を使えば良い

<script setup lang="ts">
useHead({
  script: [
    {
      src: 'example.js',
      tagPriority: 1,
    },
  ],
})
</script>

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

https://line.me/ti/g2/eEPltQ6Tzh3pYAZV8JXKZqc7PJ6L0rpm573dcQ

プロフィール・経歴

https://github.com/YumaInaura/YumaInaura

公開日時

2025-01-07

https://qiita.com/YumaInaura/items/4d38e6b4edfda3a90510

Discussion