Skip to content

Commit f9c66c3

Browse files
Steven Hokevinmarrec
authored andcommitted
docs(zh-Hant): add chinese traditional translation (nuxt#253)
* docs(zh-Hant): add chinese traditional translation * remove: remove zh-Hant unnecessary files
1 parent f2cda9a commit f9c66c3

File tree

14 files changed

+857
-1
lines changed

14 files changed

+857
-1
lines changed

docs/.vuepress/config.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ module.exports = {
2121
lang: 'pt',
2222
title: 'Nuxt TypeScript',
2323
description: 'Suporte de Typescript para Nuxt.js'
24+
},
25+
'/zh-Hant/' : {
26+
lang: 'zh-Hant',
27+
title: 'Nuxt TypeScript',
28+
description: 'Nuxt.js 的 Typescript 支援'
2429
}
2530
},
2631
plugins: [
@@ -115,7 +120,26 @@ module.exports = {
115120
link: '/examples/options-api/minimal'
116121
}
117122
]
118-
}
123+
},
124+
'/zh-Hant/': {
125+
label: '繁體中文',
126+
selectText: '語言',
127+
editLinkText: '在 GitHub 上編輯此頁',
128+
sidebar: {
129+
'/examples': getExamplesSidebar(),
130+
'/zh-Hant/': getMainSidebar('/zh-Hant', '快速入門', '更多使用方式')
131+
},
132+
nav: [
133+
{
134+
text: '導覽',
135+
link: '/zh-Hant/guide/'
136+
},
137+
{
138+
text: '範例',
139+
link: '/examples/options-api/minimal'
140+
}
141+
]
142+
},
119143
}
120144
}
121145
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# 元件
2+
3+
[**單一元件檔 (SFC)**](https://vuejs.org/v2/guide/single-file-components.html) 時, `script` 標籤必須指定成 `ts` 語言。
4+
```html
5+
<script lang="ts">
6+
// 這裡編寫 TypeScript 程式碼
7+
</script>
8+
```
9+
10+
## 模板
11+
12+
<<< @/cookbook/components/template.html
13+
14+
## Script
15+
16+
17+
<tabs :options="{ useUrlFragment: false }">
18+
<tab name="Options API">
19+
20+
<<< @/cookbook/components/script.options-api.ts
21+
22+
</tab>
23+
<tab name="Composition API">
24+
25+
使用 [@vue/composition-api](https://github.com/vuejs/composition-api) 擴充元件
26+
27+
::: tip Plugin 安裝方法
28+
29+
```js
30+
// plugins/composition-api.js
31+
import Vue from 'vue'
32+
import VueCompositionApi from '@vue/composition-api'
33+
34+
Vue.use(VueCompositionApi)
35+
```
36+
37+
```js
38+
// nuxt.config.js
39+
export default {
40+
plugins: ['@/plugins/composition-api']
41+
}
42+
```
43+
44+
此 擴充元件 註冊後才能讓 `steup` 在元件中產生作用。
45+
46+
:::
47+
48+
<<< @/cookbook/components/script.composition-api.ts
49+
50+
</tab>
51+
<tab name="Class API">
52+
53+
透過 [vue-property-decorator](https://github.com/kaorun343/vue-property-decorator) 來使用 [vue-class-component](https://github.com/vuejs/vue-class-component)
54+
55+
<<< @/cookbook/components/script.class-api.ts
56+
57+
</tab>
58+
</tabs>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# 設定 (Runtime)
2+
3+
```ts
4+
import { Configuration } from '@nuxt/types'
5+
6+
const config: Configuration = {
7+
// 透過 自動完成 以及 型別檢查 定義設定
8+
}
9+
10+
export default config
11+
```

docs/zh-Hant/cookbook/middlewares.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# 中介層
2+
3+
```ts
4+
import { Middleware } from '@nuxt/types'
5+
6+
const myMiddleware: Middleware = (context) => {
7+
// 使用 context
8+
}
9+
10+
export default myMiddleware
11+
```

docs/zh-Hant/cookbook/modules.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# 模組 (Runtime)
2+
3+
```ts
4+
import { Module } from '@nuxt/types'
5+
6+
interface Options {
7+
a: boolean
8+
b: number
9+
c: string
10+
}
11+
12+
const myModule: Module<Options> = function (moduleOptions) {
13+
// 使用 this, this.options, this.nuxt
14+
// 使用 moduleOptions
15+
}
16+
17+
export default myModule
18+
19+
// 如果要將這個模組發佈成 npm 套件時,必要使用
20+
// export const meta = require('./package.json')
21+
```

docs/zh-Hant/cookbook/plugins.md

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# 擴充元件
2+
3+
## I. 注入到 Vue 實例
4+
5+
### Plugin
6+
7+
```ts
8+
declare module 'vue/types/vue' {
9+
interface Vue {
10+
$myInjectedFunction(message: string): void
11+
}
12+
}
13+
14+
Vue.prototype.$myInjectedFunction = (message: string) => console.log(message)
15+
```
16+
17+
### 使用方法
18+
19+
```html
20+
<template>
21+
<div>
22+
<button @click="$myInjectedFunction()">Click me !</button>
23+
<button @click="someMethod">Click me !</button>
24+
</div>
25+
</template>
26+
27+
<script lang="ts">
28+
import Vue from 'vue'
29+
30+
export default Vue.extend({
31+
mounted () {
32+
this.$myInjectedFunction('works in mounted')
33+
}
34+
})
35+
</script>
36+
```
37+
38+
## II. 注入到 context
39+
40+
### Plugin
41+
42+
```ts
43+
import { Plugin } from '@nuxt/types'
44+
45+
declare module '@nuxt/types' {
46+
interface Context {
47+
$myInjectedFunction(message: string): void
48+
}
49+
}
50+
51+
const myPlugin: Plugin = (context) => {
52+
context.$myInjectedFunction = (message: string) => console.log(message)
53+
}
54+
55+
export default myPlugin
56+
```
57+
58+
### 使用方法
59+
60+
```html
61+
<script lang="ts">
62+
import Vue from 'vue'
63+
64+
export default Vue.extend({
65+
asyncData (context) {
66+
context.$myInjectedFunction('works in asyncData')
67+
}
68+
})
69+
</script>
70+
```
71+
72+
## III. 兩者一起注入
73+
74+
### Plugin
75+
76+
```ts
77+
import { Plugin } from '@nuxt/types'
78+
79+
declare module 'vue/types/vue' {
80+
interface Vue {
81+
$myInjectedFunction(message: string): void
82+
}
83+
}
84+
85+
declare module '@nuxt/types' {
86+
interface NuxtAppOptions {
87+
$myInjectedFunction(message: string): void
88+
}
89+
}
90+
91+
declare module 'vuex/types/index' {
92+
interface Store<S> {
93+
$myInjectedFunction(message: string): void
94+
}
95+
}
96+
97+
const myPlugin: Plugin = (context, inject) => {
98+
inject('myInjectedFunction', (message: string) => console.log(message))
99+
}
100+
101+
export default myPlugin
102+
```
103+
104+
### 使用方法
105+
106+
```html
107+
<script lang="ts">
108+
import Vue from 'vue'
109+
110+
export default Vue.extend({
111+
mounted () {
112+
this.$myInjectedFunction('works in mounted')
113+
},
114+
asyncData (context) {
115+
context.app.$myInjectedFunction('works in asyncData')
116+
}
117+
})
118+
</script>
119+
```
120+
121+
::: tip
122+
請注意, `inject` 是在 `context.app` 中注入,並不會存在於 `context` 中。
123+
:::
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
next: false
3+
---
4+
5+
# 伺服器渲染中介層 (Runtime)
6+
7+
```ts
8+
import { ServerMiddleware } from '@nuxt/types'
9+
10+
const myServerMiddleware: ServerMiddleware = function (req, res, next) {
11+
// 使用 req, res, next
12+
}
13+
14+
export default myServerMiddleware
15+
```

0 commit comments

Comments
 (0)