Vue.js は Props の概念を提供します

Linda Hamilton
リリース: 2024-10-17 06:08:29
オリジナル
825 人が閲覧しました

Hello! Props は Vue.js で最も必要な部分の 1 つであり、コンポーネント間の情報交換を可能にします。小道具の使用は、setup 関数内で行われます。以下は小道具 <スクリプトのセットアップ>です。 以下の操作方法を詳しく見ることができます:

Vue.js da Props tushunchasi

  1. プロップの定義: defineProps 関数は、Vue.js でプロップを定義するために使用されます。 defineProps オブジェクトは、プロパティのタイプとプロパティを定義するために使用されます。
<template>
  <div>
    <h1>{{ title }}</h1>
    <p>{{ message }}</p>
  </div>
</template>

<script setup>
import { defineProps } from 'vue'

// Props-larni aniqlash
const props = defineProps({
  title: {
    type: String,
    required: true
  },
  message: {
    type: String,
    default: 'Default message'
  }
})
</script>
ログイン後にコピー

ここで、props オブジェクトはタイトルとメッセージの小道具を定義します。 title prop タイプは String で必須 (required: true)、message は String タイプとデフォルト値 (Default message) を持ちます。

  1. プロップの使用: defineProps 関数で定義された props は、