diff --git a/content/ja/9.workspace/1.todo-list/2.list-rendering/.template/files/app.vue b/content/ja/9.workspace/1.todo-list/2.list-rendering/.template/files/app.vue new file mode 100644 index 00000000..ef04b48c --- /dev/null +++ b/content/ja/9.workspace/1.todo-list/2.list-rendering/.template/files/app.vue @@ -0,0 +1,286 @@ + + + + + diff --git a/content/ja/9.workspace/1.todo-list/2.list-rendering/.template/files/assets/check-circle-gray.svg b/content/ja/9.workspace/1.todo-list/2.list-rendering/.template/files/assets/check-circle-gray.svg new file mode 100644 index 00000000..8b64f7f4 --- /dev/null +++ b/content/ja/9.workspace/1.todo-list/2.list-rendering/.template/files/assets/check-circle-gray.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/content/ja/9.workspace/1.todo-list/2.list-rendering/.template/files/assets/check-circle-green.svg b/content/ja/9.workspace/1.todo-list/2.list-rendering/.template/files/assets/check-circle-green.svg new file mode 100644 index 00000000..b260e8a3 --- /dev/null +++ b/content/ja/9.workspace/1.todo-list/2.list-rendering/.template/files/assets/check-circle-green.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/content/ja/9.workspace/1.todo-list/2.list-rendering/.template/files/assets/close-gray.svg b/content/ja/9.workspace/1.todo-list/2.list-rendering/.template/files/assets/close-gray.svg new file mode 100644 index 00000000..751b33ff --- /dev/null +++ b/content/ja/9.workspace/1.todo-list/2.list-rendering/.template/files/assets/close-gray.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/content/ja/9.workspace/1.todo-list/2.list-rendering/.template/files/assets/person-gray.svg b/content/ja/9.workspace/1.todo-list/2.list-rendering/.template/files/assets/person-gray.svg new file mode 100644 index 00000000..246115d7 --- /dev/null +++ b/content/ja/9.workspace/1.todo-list/2.list-rendering/.template/files/assets/person-gray.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/content/ja/9.workspace/1.todo-list/2.list-rendering/.template/index.ts b/content/ja/9.workspace/1.todo-list/2.list-rendering/.template/index.ts new file mode 100644 index 00000000..ef7e2068 --- /dev/null +++ b/content/ja/9.workspace/1.todo-list/2.list-rendering/.template/index.ts @@ -0,0 +1,10 @@ +import type { GuideMeta } from '~/types/guides' + +export const meta: GuideMeta = { + startingFile: 'app.vue', + features: { + terminal: false, + fileTree: false, + navigation: false, + }, +} diff --git a/content/ja/9.workspace/1.todo-list/2.list-rendering/.template/solutions/app.vue b/content/ja/9.workspace/1.todo-list/2.list-rendering/.template/solutions/app.vue new file mode 100644 index 00000000..67b6c5e3 --- /dev/null +++ b/content/ja/9.workspace/1.todo-list/2.list-rendering/.template/solutions/app.vue @@ -0,0 +1,286 @@ + + + + + diff --git a/content/ja/9.workspace/1.todo-list/2.list-rendering/.template/solutions/assets/check-circle-gray.svg b/content/ja/9.workspace/1.todo-list/2.list-rendering/.template/solutions/assets/check-circle-gray.svg new file mode 100644 index 00000000..8b64f7f4 --- /dev/null +++ b/content/ja/9.workspace/1.todo-list/2.list-rendering/.template/solutions/assets/check-circle-gray.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/content/ja/9.workspace/1.todo-list/2.list-rendering/.template/solutions/assets/check-circle-green.svg b/content/ja/9.workspace/1.todo-list/2.list-rendering/.template/solutions/assets/check-circle-green.svg new file mode 100644 index 00000000..b260e8a3 --- /dev/null +++ b/content/ja/9.workspace/1.todo-list/2.list-rendering/.template/solutions/assets/check-circle-green.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/content/ja/9.workspace/1.todo-list/2.list-rendering/.template/solutions/assets/close-gray.svg b/content/ja/9.workspace/1.todo-list/2.list-rendering/.template/solutions/assets/close-gray.svg new file mode 100644 index 00000000..751b33ff --- /dev/null +++ b/content/ja/9.workspace/1.todo-list/2.list-rendering/.template/solutions/assets/close-gray.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/content/ja/9.workspace/1.todo-list/2.list-rendering/.template/solutions/assets/person-gray.svg b/content/ja/9.workspace/1.todo-list/2.list-rendering/.template/solutions/assets/person-gray.svg new file mode 100644 index 00000000..246115d7 --- /dev/null +++ b/content/ja/9.workspace/1.todo-list/2.list-rendering/.template/solutions/assets/person-gray.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/content/ja/9.workspace/1.todo-list/2.list-rendering/index.md b/content/ja/9.workspace/1.todo-list/2.list-rendering/index.md new file mode 100644 index 00000000..cfe14479 --- /dev/null +++ b/content/ja/9.workspace/1.todo-list/2.list-rendering/index.md @@ -0,0 +1,63 @@ +--- +ogImage: true +--- + +# リストレンダリング + +Vueでは `v-for` ディレクティブを使って配列に基づいて項目のリストをレンダリングできます。これは ToDoリストのようなデータの一覧表示に非常に便利です。 + +## `v-for` の基本 + +`v-for` ディレクティブでは、`item in items` という形式の特別な構文が必要になります。ここで、`items` は元のデータの配列を指し、`item` は反復処理の対象となっている配列要素のエイリアスを指します: + +```vue +
  • + {{ item.message }} +
  • +``` + +重要なポイント: +- `:key` 属性を指定することで、Vue に各ノードを一意に追跡するためのヒントを与えます +- `item in items` の形式で、配列の各要素を順番に処理します + +## 現在の実装の課題 + +プレイグラウンドで ToDo データをテーブルで表示していますが、配列の1件目のデータ `todos[0]` のみを直接参照して表示しています: + +```vue + + {{ todos[0].done }} + {{ todos[0].title }} + {{ todos[0].note }} + {{ todos[0].dueDate }} + +``` + +この方法では: +- 1件目のデータしか表示されない +- データが増えても自動で表示されない + +## チャレンジ + +現在の固定インデックス `[0]` による参照を `v-for` を使った動的なレンダリングに変更してください: + +1. `` 内の固定の `` 要素を `v-for` を使って書き換えます +2. `v-for="todo in todos"` を使って全ての ToDoアイテムを動的にレンダリングします +3. 各項目に一意の `:key="todo.id"` 属性を指定します + +::note +`key` 属性は、Vue に各ノードを一意に追跡するためのヒントを与え、既存の要素を再利用して並べ替えを適用できるようにする際に必要となります。 +:: + +## 実装後の効果 + +`v-for` を実装すると: +- 配列内の全てのToDoアイテムが表示される +- データが追加・削除されても自動で表示が更新される +- より保守性の高いコードになる + +もし行き詰まったら、以下のボタンをクリックして解答を見ることができます。 + +:ButtonShowSolution + +`v-for` を使うことで動的なデータ表示がとても簡単になりましたね! \ No newline at end of file