Nuxt.js3 変数を使用する

Nuxt.js3 変数を使用する

Nuxt.js3で変数を使用する手順を記述しておきます。マスタッシュ構文を使用します。

環境

  • OS  ubuntu23.10
  • node v20.13.1
  • npm 10.8.0
  • Nuxt.js v3.11.2

変数を使用

マスタッシュ構文である「{{}}」と、setupを使用することで可能です。

<script setup lang="ts">

const msg1 = ref<string>("Hello world!!");
const msg2 = ref<string>("Hello world2!!");

</script>

<template>
  <div>
    <h1>{{ msg1 }}</h1>
    <h1>{{ msg1 }}</h1>
    <h2>{{ msg2 }}</h2>
  </div>
</template>

実行結果