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?

[Vue] コンポーネント props

0
Posted at

vue.js のチュートリアル
propsについて。

子コンポーネントは、親コンポーネントから props を介して入力を受け取る。

子コンポーネントの作成。

子コンポーネントに受け入れる props を宣言する。

<script setup>
const props = defineProps({
  msg: String
})
</script>

defineProps() って初めて見た。これを使うのか。

あとは、前回と同様にテンプレートを定義する。

<template>
  <h2>{{ msg || 'No props passed yet' }}</h2>
</template>

親コンポーネント側

呼び出し側はあんまり変わらない。
こんな感じでpropsを指定できる。
子コンポーネントの方で、msg を宣言してるので、msg= とする。

<ChildComp :msg="greeting" />

全体。

<script setup>
import { ref } from 'vue'
import ChildComp from './ChildComp.vue'

const greeting = ref('Hello from parent')
</script>

<template>
  <ChildComp :msg="greeting" />
</template>

stackblitzで書いた。

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?