Skip to content

Commit 55861e8

Browse files
authored
chore: overall vue section (#62)
* chore: overall * chore: disable autofix.ci
1 parent 0726c2a commit 55861e8

File tree

9 files changed

+84
-85
lines changed

9 files changed

+84
-85
lines changed

.github/workflows/autofix.yml

+25-25
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
name: autofix.ci
1+
# name: autofix.ci
22

3-
on:
4-
push:
5-
branches:
6-
- main
3+
# on:
4+
# push:
5+
# branches:
6+
# - main
77

8-
pull_request:
9-
branches:
10-
- main
8+
# pull_request:
9+
# branches:
10+
# - main
1111

12-
jobs:
13-
autofix:
14-
runs-on: ubuntu-latest
15-
timeout-minutes: 10
12+
# jobs:
13+
# autofix:
14+
# runs-on: ubuntu-latest
15+
# timeout-minutes: 10
1616

17-
steps:
18-
- uses: actions/checkout@v4
17+
# steps:
18+
# - uses: actions/checkout@v4
1919

20-
- uses: pnpm/action-setup@v4
20+
# - uses: pnpm/action-setup@v4
2121

22-
- name: Use Node.js lts/*
23-
uses: actions/setup-node@v4
24-
with:
25-
node-version: lts/*
26-
cache: pnpm
22+
# - name: Use Node.js lts/*
23+
# uses: actions/setup-node@v4
24+
# with:
25+
# node-version: lts/*
26+
# cache: pnpm
2727

28-
- name: Install
29-
run: pnpm install --frozen-lockfile
28+
# - name: Install
29+
# run: pnpm install --frozen-lockfile
3030

31-
- name: Lint
32-
run: pnpm run lint --fix
31+
# - name: Lint
32+
# run: pnpm run lint --fix
3333

34-
- uses: autofix-ci/action@v1
34+
# - uses: autofix-ci/action@v1

content/0.index.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ ogImage:
1515

1616
## Nuxt とは?
1717

18-
Nuxt は、[Vue.js](https://vuejs.org) を使用して、型安全でパフォーマンスが高く本番環境に適したフルスタックの Web アプリケーションやウェブサイトを作成するための直感的で拡張可能な方法を提供する、無料で[オープンソースのフレームワーク](https://github.com/nuxt/nuxt)です。Nuxt はベンダーロックインがなく、アプリケーションを[**どこでも、エッジ上でも**](https://nuxt.com/blog/nuxt-on-the-edge)デプロイすることができます。
18+
Nuxt は、[Vue.js](https://vuejs.org) を使用して、型安全でパフォーマンスが高く本番環境に適したフルスタックの Web アプリケーションやウェブサイトを作成するための直感的で拡張可能な方法を提供する、無料で [オープンソースのフレームワーク](https://github.com/nuxt/nuxt) です。Nuxt はベンダーロックインがなく、アプリケーションを [**どこでも、エッジ上でも**](https://nuxt.com/blog/nuxt-on-the-edge) デプロイすることができます。
1919

2020
## はじめに
2121

22-
このチュートリアルでは、HTML、CSS、JavaScript の基本的な概念に既に精通していることを前提としています。Nuxt は[Vue](https://vuejs.org) の上に構築されたフルスタックフレームワークのため、Vue の基本的なチュートリアルも提供しています。
22+
このチュートリアルでは、HTML、CSS、JavaScript の基本的な概念に既に精通していることを前提としています。Nuxt は [Vue](https://vuejs.org) の上に構築されたフルスタックフレームワークのため、Vue の基本的なチュートリアルも提供しています。
2323

2424
以下のトピックをクリックして学習を始めてください:
2525

content/1.vue/2.reactivity/.template/files/app.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<script setup>
1+
<script setup lang="ts">
22
const count = ref(1)
33
const doubled = computed(() => count.value * 2)
44

content/1.vue/2.reactivity/.template/solutions/app.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
<script setup>
1+
<script setup lang="ts">
22
const count = ref(1)
33
const multiplier = ref(2)
44
const result = computed(() => count.value * multiplier.value)
55
66
function increment() {
77
count.value++
88
}
9+
910
function multiply() {
1011
multiplier.value++
1112
}

content/1.vue/2.reactivity/index.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
ogImage: true
33
---
44

5-
# Reactivity Part 1
5+
# リアクティビティー パート1
66

7-
Vue はデータの変更を監視して、変更された時に更新を自動的にトリガーする [優れたリアクティビティシステム](https://ja.vuejs.org/guide/essentials/reactivity-fundamentals) を提供していて、常に最新のデータを UI に反映させることができます。Vue のリアクティビティは、`ref``reactive``computed``watch` があります。
7+
Vue はデータの変更を監視して、変更された時に更新を自動的にトリガーする [優れたリアクティビティシステム](https://ja.vuejs.org/guide/essentials/reactivity-fundamentals) を提供していて、常に最新のデータを UI に反映させることができます。Vue のリアクティビティは、`ref``computed``watch` があります。
88

99
- [`ref()`](https://ja.vuejs.org/api/reactivity-core#ref) は単一の値を保持するためのコンテナを作成し、値が変更された時に自動的に追跡できるようにします。値は `.value` を通してアクセスすることができます。
1010

@@ -18,7 +18,7 @@ Vue はデータの変更を監視して、変更された時に更新を自動
1818
**注意**: `<template>` 内で参照された場合、refs は Vue によって自動的にアンラップされます。`.value` は、`<script>` 内や Vue コンポーネント外の JavaScript でアクセスする時にのみ必要になります。
1919
::
2020

21-
## Challenge
21+
## チャレンジ
2222

2323
では、実際にやってみましょう!
2424
現在 `2` 倍にハードコードされている乗数をリアクティブに更新可能にするコードに変更してみましょう。
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,42 @@
11
<script setup lang="ts">
2-
let todoId = 1
2+
const id = ref(1)
33
4-
const todoData = reactive({
5-
loading: false,
6-
data: null,
7-
})
4+
const loading = ref(false)
5+
6+
const data = ref<{
7+
userId: number
8+
id: number
9+
title: string
10+
completed: boolean
11+
} | null>(null)
812
913
function increment() {
10-
todoId++
14+
id.value++
1115
}
1216
1317
async function fetchTodo() {
14-
todoData.loading = true
18+
loading.value = true
1519
try {
16-
const res = await fetch(`https://jsonplaceholder.typicode.com/todos/${todoId}`)
17-
todoData.data = await res.json()
20+
const res = await fetch(`https://jsonplaceholder.typicode.com/todos/${id.value}`)
21+
data.value = await res.json()
1822
}
1923
finally {
20-
todoData.loading = false
24+
loading.value = false
2125
}
2226
}
2327
24-
watch(todoId, fetchTodo, { immediate: true })
28+
watch(id, fetchTodo, { immediate: true })
2529
</script>
2630

2731
<template>
2832
<div>
29-
<p>ID: {{ todoId }}</p>
30-
<button type="button" :disabled="todoData.loading" @click="increment">
33+
<p>ID: {{ id }}</p>
34+
<button type="button" :disabled="loading" @click="increment">
3135
次の TODO アイテムを取得
3236
</button>
33-
<p v-if="todoData.loading">
37+
<p v-if="loading">
3438
Loading...
3539
</p>
36-
<pre v-else>{{ todoData.data }}</pre>
40+
<pre v-else>{{ data }}</pre>
3741
</div>
3842
</template>
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,41 @@
11
<script setup lang="ts">
2-
const todoData = reactive({
2+
const state = ref<{
3+
id: number
4+
loading: boolean
5+
data: { userId: number, id: number, title: string, completed: boolean } | null
6+
}>({
37
id: 1,
48
loading: false,
59
data: null,
610
})
711
812
function increment() {
9-
todoData.id++
13+
state.value.id++
1014
}
1115
1216
async function fetchTodo() {
13-
todoData.loading = true
17+
state.value.loading = true
1418
try {
15-
const res = await fetch(`https://jsonplaceholder.typicode.com/todos/${todoData.id}`)
16-
todoData.data = await res.json()
19+
const res = await fetch(`https://jsonplaceholder.typicode.com/todos/${state.value.id}`)
20+
state.value.data = await res.json()
1721
}
1822
finally {
19-
todoData.loading = false
23+
state.value.loading = false
2024
}
2125
}
2226
23-
watch(() => todoData.id, fetchTodo, { immediate: true })
24-
25-
fetchTodo()
27+
watch(() => state.value.id, fetchTodo, { immediate: true })
2628
</script>
2729

2830
<template>
2931
<div>
30-
<p>ID: {{ todoData.id }}</p>
31-
<button type="button" :disabled="todoData.loading" @click="increment">
32-
Next Todo
32+
<p>ID: {{ state.id }}</p>
33+
<button type="button" :disabled="state.loading" @click="increment">
34+
次の TODO アイテムを取得
3335
</button>
34-
<p v-if="todoData.loading">
36+
<p v-if="state.loading">
3537
Loading...
3638
</p>
37-
<pre v-else>{{ todoData.data }}</pre>
39+
<pre v-else>{{ state.data }}</pre>
3840
</div>
3941
</template>

content/1.vue/3.reactivity-2/index.md

+15-23
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,34 @@
22
ogImage: true
33
---
44

5-
# Reactivity Part 2
5+
# リアクティビティー パート2
66

7-
前章で `ref``computed` を使った基本的なデータバインディングを学びました。本章では、`reactive``watch` について学びましょう。この章で基本的なリアクティビティシステムをマスターできます!
7+
前章で `ref``computed` を使った基本的なデータバインディングを学びました。本章では、`watch` について学びましょう。この章で基本的なリアクティビティシステムをマスターできます!
88

9-
- [`reactive()`](https://ja.vuejs.org/api/reactivity-core#reactive) はオブジェクト全体をリアクティブなデータとして扱うことができます。複数のプロパティを持つオブジェクトを管理できます。
10-
11-
- [`watch()`](https://ja.vuejs.org/api/reactivity-core#watch) はリアクティブなデータの変化を監視し、変化があったときに特定の処理を実行することができます。
12-
13-
`reactive` で宣言された値は、JavaScript の[プロキシ](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Proxy)として返ってくるため、以下のように通常のオブジェクトと同じように操作することができます。
9+
[`watch()`](https://ja.vuejs.org/api/reactivity-core#watch) はリアクティブなデータの変化を監視し、変化があったときに特定の処理を実行することができます。\
10+
`watch``computed` と同様にリアクティブ値の変化に応じて作用しますが、主に `console.log``fetch` のような副作用をリアクティブに実行するときに使います。
1411

1512
```ts
16-
const counter = reactive({ count: 0 })
17-
counter.count++ // .value は不要
18-
console.log(counter.count) // -> 1
19-
```
13+
const count = ref(0)
2014

21-
::note
22-
**注意**: よくある間違いとして、`ref` はプリミティブな値のみに対応し、オブジェクトには `reactive` を使うという誤解があります。実際は `ref` でも `ref({ count: 0 })` のようにオブジェクトをリアクティブな値として宣言することができます。
23-
また、`reactive` には [いくつかの制限事項がある](https://ja.vuejs.org/guide/essentials/reactivity-fundamentals#limitations-of-reactive) ため、リアクティブな状態を宣言する際は基本的に `ref` を用いるのが推奨されます。
24-
::
15+
watch(count, (newValue, oldValue) => {
16+
console.log(`count changed from ${oldValue} to ${newValue}`)
17+
})
18+
```
2519

26-
`watch``computed` と同様にリアクティブ値の変化に応じて作用しますが、主に `console.log``fetch` のような副作用をリアクティブに実行するときに使います。
2720
プレイグラウンドでは、サーバーで管理している TODO アイテムを表示していますが、表示する ID が変化したときに新しいアイテムを取得するために `watch` による監視をしています。
2821

2922
`watch` に関する詳しい説明は [ウォッチャーガイド](https://ja.vuejs.org/guide/essentials/watchers) を参照してください。
3023

31-
## チャレンジ問題
24+
## チャレンジ
3225

33-
今のプレイグラウンドは、TODO アイテムに関するデータを `todoId``todoData` の 2 つのリアクティブ値として管理しています。これらを 1 つの `todoData` にまとめましょう。
34-
これらのステップを実行することで、`reactive``watch` の理解を深めることができるのでぜひ挑戦してみてください!
26+
今のプレイグラウンドは、TODO アイテムに関するデータを `id``data` の 2 つのリアクティブ値として管理しています。これらを 1 つの `state` という ref オブジェクトにまとめてみましょう。
3527

36-
1. `todoData``id` プロパティを追加し、`todoId` を消しましょう
37-
2. エラー箇所にしたがって、`todoId` と書いてある箇所を `todoData.id` に変えましょう
38-
- これで `watch` 以外のエラーは解消されるはずです。
28+
1. `state` という変数を作成し、`id` `data``loading``state` にまとめましょう
29+
2. エラー箇所にしたがって、`id`, `loading`, `data` と書いてある箇所はそれぞれ `state.value.id`, `state.value.loading`, `state.value.data` に書き換えましょう
30+
- template 内では `.value` を書く必要はありません
3931
3. `watch` の第一引数をゲッター関数に変えましょう。
40-
- `todoData.id` のままだと数値を渡していることになるため、`watch` が変化を補足できません。
32+
- `state.value.id` のままだと数値を渡していることになるため、`watch` が変化を補足できません。
4133

4234
もし手詰まりになったら、解決策を確認するためのボタンをクリックして、ヒントを得ることができます。
4335
:ButtonShowSolution{.bg-faded.px4.py2.rounded.border.border-base.hover:bg-active.hover:text-primary.hover:border-primary:50}

content/1.vue/4.composition-api/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Composables の主な特徴は以下の通りです。
1010

1111
Nuxt では、`composables/` ディレクトリに Composables なロジックを格納することが多く、[自動インポート](https://nuxt.com/docs/examples/features/auto-imports) の対象になります。
1212

13-
## チャレンジ問題
13+
## チャレンジ
1414

1515
それでは、これらの特徴を踏まえて以下のステップでロジックを Composables として切り出し、再利用してみましょう。
1616

0 commit comments

Comments
 (0)