0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Vue3】propsの書き方

Posted at

コード

App.vue
<template>
  <TitleTemplate :main-title="タイトル" />
</template>

<script setup>
import TitleTemplate from 'TitleTemplate.vue'
</script>
TitleTemplate.vue
<template>
  <p>{{ mainTitle + subTitle }}</p>
</template>

<script setup>
defineProps({
  // 必須の場合
  mainTitle: {
    type: String,
    required: true,
  },
  // デフォルト値を設定する場合
  subTitle: {
    type: String,
    default: 'デフォルト文言'
  },
})
</script>

scriptでpropsを使用する場合は、変数に格納する。

<script setup>
const props = defineProps({
  title: {
    type: String,
    required: true,
  },
})

const test = props.title
</script>

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?