diff --git a/content/1.vue/5.components/.template/files/ChildComponent.vue b/content/1.vue/5.components/.template/files/ChildComponent.vue new file mode 100644 index 0000000..a9d66eb --- /dev/null +++ b/content/1.vue/5.components/.template/files/ChildComponent.vue @@ -0,0 +1,29 @@ + + + + + diff --git a/content/1.vue/5.components/.template/files/app.vue b/content/1.vue/5.components/.template/files/app.vue new file mode 100644 index 0000000..85b7e10 --- /dev/null +++ b/content/1.vue/5.components/.template/files/app.vue @@ -0,0 +1,21 @@ + + + diff --git a/content/1.vue/5.components/.template/index.ts b/content/1.vue/5.components/.template/index.ts index ef7e206..7affa29 100644 --- a/content/1.vue/5.components/.template/index.ts +++ b/content/1.vue/5.components/.template/index.ts @@ -4,7 +4,7 @@ export const meta: GuideMeta = { startingFile: 'app.vue', features: { terminal: false, - fileTree: false, + fileTree: true, navigation: false, }, } diff --git a/content/1.vue/5.components/.template/solutions/ChildComponent.vue b/content/1.vue/5.components/.template/solutions/ChildComponent.vue new file mode 100644 index 0000000..2138985 --- /dev/null +++ b/content/1.vue/5.components/.template/solutions/ChildComponent.vue @@ -0,0 +1,25 @@ + + + + + diff --git a/content/1.vue/5.components/.template/solutions/app.vue b/content/1.vue/5.components/.template/solutions/app.vue new file mode 100644 index 0000000..8bfd556 --- /dev/null +++ b/content/1.vue/5.components/.template/solutions/app.vue @@ -0,0 +1,16 @@ + + + diff --git a/content/1.vue/5.components/index.md b/content/1.vue/5.components/index.md index 0eac4eb..a4d6fb4 100644 --- a/content/1.vue/5.components/index.md +++ b/content/1.vue/5.components/index.md @@ -1 +1,117 @@ -# Components +--- +ogImage: true +--- + +# コンポーネント + +Vue.js のコンポーネントは、UI を小さな再利用可能な部分に分割するための基本的な単位です。\ +特に Single File Components (SFC) を使うことで、HTML、CSS、および JavaScript を 1 つの `.vue` ファイルにまとめることができます。 + +## 基本的な SFC の構造 + +SFC は基本的に以下のような ` + + + + +``` + +この例では、` + + +``` + +## コンポーネント間のデータの受け渡し + +Vue コンポーネント間でデータをやり取りする基本的な方法として、`props` と `emit` を使用します。 + +- `props`: 親コンポーネントから子コンポーネントにデータを渡すための方法です。 +- `emit`: 子コンポーネントから親コンポーネントにイベントを発火するための方法です。 + +それぞれ `defineProps`, `defineEmits` で登録します。\ +使い方は右側のプレイグラウンド、または [API ドキュメント](https://ja.vuejs.org/api/sfc-script-setup.html#defineprops-defineemits)から確認できます。 + +## 双方向バインディング + +コンポーネント上で `v-model` を使うことで双方向バインディングを実装できます。\ +以下の例では、コンポーネント中で宣言された `value` が `` の値とバインドされ、`` の入力値が `value` に反映されます。 + +```vue + + + +``` + +また、SFC で `defineModel` を使うことで、親コンポーネントから `v-model` 経由で使用できる双方向バインディングの `props` を宣言できます。 + +```vue + + + + +``` + +```vue + + + + +``` + +## チャレンジ + +プレイグラウンドの `ChildComponent.vue` は `props` と `emit` を使って双方向バインディングを実現しています。\ +これを `defineModel` を使って簡潔に書き直してみましょう。 + +もし手詰まりになったら、解決策を確認するためのボタンをクリックして、ヒントを得ることができます。 + +:ButtonShowSolution{.bg-faded.px4.py2.rounded.border.border-base.hover:bg-active.hover:text-primary.hover:border-primary:50} diff --git a/content/1.vue/5.summary/.template/index.ts b/content/1.vue/6.summary/.template/index.ts similarity index 100% rename from content/1.vue/5.summary/.template/index.ts rename to content/1.vue/6.summary/.template/index.ts diff --git a/content/1.vue/5.summary/index.md b/content/1.vue/6.summary/index.md similarity index 100% rename from content/1.vue/5.summary/index.md rename to content/1.vue/6.summary/index.md