Skip to content

Commit 4a08349

Browse files
authored
docs: translate content form Japanese to English (#199)
* add content of concepts/auto-import * update examples and solutions * add content of concepts/middleware
1 parent 0ee1df6 commit 4a08349

File tree

21 files changed

+277
-0
lines changed

21 files changed

+277
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script setup lang="ts">
2+
const count = ref(0)
3+
</script>
4+
5+
<template>
6+
<button type="button" @click="count++">
7+
count is: {{ count }}
8+
</button>
9+
10+
<Counter />
11+
</template>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script setup lang="ts">
2+
const { count, increment } = useCounter()
3+
</script>
4+
5+
<template>
6+
<button type="button" @click="increment">
7+
count is: {{ count }}
8+
</button>
9+
</template>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export function useCounter() {
2+
const count = ref(0)
3+
function increment() {
4+
count.value++
5+
}
6+
7+
return { count, increment }
8+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Challenge
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type { GuideMeta } from '~/types/guides'
2+
3+
export const meta: GuideMeta = {
4+
startingFile: 'app.vue',
5+
features: {
6+
fileTree: true,
7+
},
8+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<script setup lang="ts">
2+
const count = ref(0)
3+
</script>
4+
5+
<template>
6+
<button type="button" @click="count++">
7+
count is: {{ count }}
8+
</button>
9+
10+
<p>double is: {{ double(count) }}</p>
11+
12+
<Counter />
13+
</template>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script setup lang="ts">
2+
const { count, increment } = useCounter()
3+
</script>
4+
5+
<template>
6+
<button type="button" @click="increment">
7+
count is: {{ count }}
8+
</button>
9+
</template>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export function useCounter() {
2+
const count = ref(0)
3+
function increment() {
4+
count.value++
5+
}
6+
7+
return { count, increment }
8+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function double(n: number): number {
2+
return n * 2
3+
}

content/2.concepts/4.auto-imports/index.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,49 @@ ogImage: true
33
---
44

55
# Auto Imports
6+
7+
Auto import is also one of Nuxt's core concepts.
8+
9+
https://nuxt.com/docs/guide/concepts/auto-imports
10+
11+
Auto import is a feature that allows components, composables, and [Vue.js API](https://vuejs.org/api/) to be automatically imported and used throughout the application without explicit imports.\
12+
Unlike traditional global declarations, Nuxt retains type information, IDE autocompletion, and hints while including only what is actually used in the production code.
13+
14+
Thanks to Nuxt's directory structure conventions, `components/`, `composables/`, and `utils/` can be automatically imported.\
15+
In this example, the `Counter.vue` component defined in the `components` directory and `useCounter.ts` defined in the `composables` directory are used without explicit imports.\
16+
In `app.vue`, the Counter component is used, and in `Counter.vue`, `useCounter()` is utilized.
17+
18+
Additionally, Nuxt provides several components, composables, and utility functions.\
19+
An example is the `NuxtLink` component introduced in the [Routing](/concepts/routing) section.\
20+
Other examples include the `useFetch()` composable for data fetching, `useRuntimeConfig()` for accessing runtime configuration, and the `navigateTo()` utility function for page navigation.\
21+
Since there are many more, refer to the official Nuxt documentation for the full list in the sections on [Components](https://nuxt.com/docs/api/components), [Composables](https://nuxt.com/docs/api/composables), and [Utils](https://nuxt.com/docs/api/utils).
22+
23+
Nuxt also supports explicit imports, which can be done using `#imports`.
24+
25+
```ts
26+
import { computed, ref } from '#imports'
27+
28+
const count = ref(1)
29+
const double = computed(() => count.value * 2)
30+
```
31+
32+
The auto import feature can be opted out in `nuxt.config.ts`.\
33+
In this case, explicit imports like the one above will be required.
34+
35+
```ts
36+
// nuxt.config.ts
37+
export default defineNuxtConfig({
38+
imports: {
39+
autoImport: false
40+
}
41+
})
42+
```
43+
44+
## Challenge
45+
46+
Try implementing an auto-importable function in the `utils/double.ts` file.
47+
48+
You can create any function, but as an example, let's implement a `double()` function that returns twice the given number.\
49+
Once you've implemented the function, use it in the template section of `app.vue` to display the doubled value on the screen.
50+
51+
:ButtonShowSolution{.bg-faded.px4.py2.rounded.border.border-base.hover:bg-active.hover:text-primary.hover:border-primary:50}

0 commit comments

Comments
 (0)