Skip to content

Commit 6da4d69

Browse files
authored
Merge pull request #179 from vuejs-jp/feat/application-api
doc: Translate application api
2 parents d78ecf2 + 26b6105 commit 6da4d69

File tree

1 file changed

+91
-91
lines changed

1 file changed

+91
-91
lines changed

src/api/application-api.md

Lines changed: 91 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,58 @@
11
# アプリケーション API
22

3-
In Vue 3, APIs that globally mutate Vue's behavior are now moved to application instances created by the new `createApp` method. In addition, their effects are now scoped to that specific application's instance:
3+
Vue 3 では、Vue の動作にグローバルな変更を与える API は、新しい `createApp` メソッドによって作成されたアプリケーションインスタンスへと移行されました。さらに、その効果が適用されるスコープは、指定したアプリケーションのインスタンス内に限定されるようになりました:
44

55
```js
66
import { createApp } from 'vue'
77

88
const app = createApp({})
99
```
1010

11-
Calling `createApp` returns an application instance. This instance provides an application context. The entire component tree mounted by the application instance share the same context, which provides the configurations that were previously "global" in Vue 2.x.
11+
`createApp` を呼び出すと、アプリケーションのインスタンスが返されます。このインスタンスはアプリケーションコンテキストを提供します。アプリケーションインスタンスによってマウントされたコンポーネントツリー全体が同じコンテキストを共有し、Vue 2.x で以前は **グローバル** であった設定を提供します。
1212

13-
In addition, since the `createApp` method returns the application instance itself, you can chain other methods after it which can be found in the following sections.
13+
加えて、 `createApp` メソッドは自身のアプリケーションインスタンスを返すため、今後のセクションにて紹介するように、メソッドに対して他のメソッドをチェーンさせることができます。
1414

1515
## component
1616

17-
- **Arguments:**
17+
- **引数:**
1818

1919
- `{string} name`
2020
- `{Function | Object} definition (optional)`
2121

22-
- **Returns:**
22+
- **返り値:**
2323

24-
- The application instance if a `definition` argument was passed
25-
- The component definition if a `definition` argument was not passed
24+
- `definition` 引数が渡されている場合、アプリケーションのインスタンス
25+
- `definition` 引数が渡されていない場合、コンポーネントの定義
2626

27-
- **Usage:**
27+
- **使用方法:**
2828

29-
Register or retrieve a global component. Registration also automatically sets the component's `name` with the given `name` parameter.
29+
グローバルコンポーネントを登録または取得します。登録すると、与えられた `name` に対して、コンポーネントの `name` が自動的に設定されます。
3030

31-
- **Example:**
31+
- **:**
3232

3333
```js
3434
import { createApp } from 'vue'
3535

3636
const app = createApp({})
3737

38-
// register an options object
38+
// オブジェクトの登録
3939
app.component('my-component', {
4040
/* ... */
4141
})
4242

43-
// retrieve a registered component
43+
// 登録済みのコンポーネントの取得
4444
const MyComponent = app.component('my-component')
4545
```
4646

47-
- **See also:** [Components](../guide/component-basics.html)
47+
- **参照:** [Components](../guide/component-basics.html)
4848

4949
## config
5050

51-
- **Usage:**
51+
- **使用方法:**
5252

53-
An object containing application configurations.
53+
アプリケーションの設定を含む場合に利用
5454

55-
- **Example:**
55+
- **:**
5656

5757
```js
5858
import { createApp } from 'vue'
@@ -61,72 +61,72 @@ const app = createApp({})
6161
app.config = {...}
6262
```
6363

64-
- **See also:** [Application Config](./application-config.html)
64+
- **参照:** [Application Config](./application-config.html)
6565

6666
## directive
6767

68-
- **Arguments:**
68+
- **引数:**
6969

7070
- `{string} name`
7171
- `{Function | Object} definition (optional)`
7272

73-
- **Returns:**
73+
- **返り値:**
7474

75-
- The application instance if a `definition` argument was passed
76-
- The directive definition if a `definition` argument was not passed
75+
- `definition` 引数が渡された場合はアプリケーションのインスタンス
76+
- `definition` 引数が渡されていない場合はディレクティブの定義
7777

78-
- **Usage:**
78+
- **使用方法:**
7979

80-
Register or retrieve a global directive.
80+
グローバルディレクティブを登録または取得します。
8181

82-
- **Example:**
82+
- **:**
8383

8484
```js
8585
import { createApp } from 'vue'
8686
const app = createApp({})
8787

88-
// register
88+
// 登録
8989
app.directive('my-directive', {
90-
// Directive has a set of lifecycle hooks:
91-
// called before bound element's parent component is mounted
90+
// ディレクティブはライフサイクルのセットをもちます:
91+
// バインドされた要素の親コンポーネントがマウントされる前に呼び出されます。
9292
beforeMount() {},
93-
// called when bound element's parent component is mounted
93+
// バインドされた要素の親コンポーネントがマウントされた後に呼び出されます。
9494
mounted() {},
95-
// called before the containing component's VNode is updated
95+
// コンポーネントが含む VNode に更新が行われる前に呼び出されます。
9696
beforeUpdate() {},
97-
// called after the containing component's VNode and the VNodes of its children // have updated
97+
// コンポーネントが含む VNode 及びその子要素に更新が行われた場合に呼び出されます。
9898
updated() {},
99-
// called before the bound element's parent component is unmounted
99+
// バインドされた要素の親コンポーネントがアンマウントされる前に呼び出されます。
100100
beforeUnmount() {},
101-
// called when the bound element's parent component is unmounted
101+
// バインドされた要素の親コンポーネントがアンマウントされた後に呼び出されます。
102102
unmounted() {}
103103
})
104104

105-
// register (function directive)
105+
// 登録 (関数ディレクティブ)
106106
app.directive('my-directive', () => {
107-
// this will be called as `mounted` and `updated`
107+
// `mounted` ならびに `updated` にて呼び出されます。
108108
})
109109

110-
// getter, return the directive definition if registered
110+
// ゲッター。登録されている場合、ディレクティブ定義を返却します。
111111
const myDirective = app.directive('my-directive')
112112
```
113113

114-
Directive hooks are passed these arguments:
114+
ディレクティブフックには、これらの要素が渡されます:
115115

116116
#### el
117117

118-
The element the directive is bound to. This can be used to directly manipulate the DOM.
118+
ディレクティブがバインドされる要素。これを利用することで、 DOM を直接操作できます。
119119

120120
#### binding
121121

122-
An object containing the following properties.
122+
このオブジェクトは、以下のプロパティを持ちます。
123123

124-
- `instance`: The instance of the component where directive is used.
125-
- `value`: The value passed to the directive. For example in `v-my-directive="1 + 1"`, the value would be `2`.
126-
- `oldValue`: The previous value, only available in `beforeUpdate` and `updated`. It is available whether or not the value has changed.
127-
- `arg`: The argument passed to the directive, if any. For example in `v-my-directive:foo`, the arg would be `"foo"`.
128-
- `modifiers`: An object containing modifiers, if any. For example in `v-my-directive.foo.bar`, the modifiers object would be `{ foo: true, bar: true }`.
129-
- `dir`: an object, passed as a parameter when directive is registered. For example, in the directive
124+
- `instance`: ディレクティブが使われているコンポーネントのインスタンス。
125+
- `value`: ディレクティブの値。例えば `v-my-directive="1 + 1"` の場合、 value `2`となります。
126+
- `oldValue`: 以前の値であり、 `beforeUpdate` および `updated` でのみ利用できます。値が変更されているかを判別できます。
127+
- `arg`: 引数がある場合はそれを含むオブジェクト。例えば `v-my-directive:foo` の場合、 arg `"foo"` となります。
128+
- `modifiers`: 修飾子がある場合はそれを含むオブジェクト。例えば `v-my-directive.foo.bar` の場合、 modifiers オブジェクトは `{ foo: true, bar: true }` となります。
129+
- `dir`: ディレクティブが登録されたとき、パラメータとして渡されるオブジェクト。例えば、このディレクティブ内では
130130

131131
```js
132132
app.directive('focus', {
@@ -136,7 +136,7 @@ app.directive('focus', {
136136
})
137137
```
138138

139-
`dir` would be the following object:
139+
`dir` は以下のオブジェクトとなります:
140140

141141
```js
142142
{
@@ -148,50 +148,50 @@ app.directive('focus', {
148148

149149
#### vnode
150150

151-
A blueprint of the real DOM element received as el argument above.
151+
el にて受け取った実際の DOM 要素の blueprint を表します。
152152

153153
#### prevNode
154154

155-
The previous virtual node, only available in the `beforeUpdate` and `updated` hooks.
155+
以前の VNode を表します。`beforeUpdate` および `updated` フックでのみ利用可能です。
156156

157157
:::tip Note
158-
Apart from `el`, you should treat these arguments as read-only and never modify them. If you need to share information across hooks, it is recommended to do so through element's [dataset](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset).
158+
`el` を除き、これらはすべて読み取り専用であり、変更してはいけません。フック間にて情報を共有したい場合、要素の[データセット](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset)を通して情報を共有することを推奨します。
159159
:::
160160

161-
- **See also:** [Custom Directives](../guide/custom-directive.html)
161+
- **参照:** [Custom Directives](../guide/custom-directive.html)
162162

163163
## mixin
164164

165-
- **Arguments:**
165+
- **引数:**
166166

167167
- `{Object} mixin`
168168

169-
- **Returns:**
169+
- **返り値:**
170170

171-
- The application instance
171+
- アプリケーションのインスタンス
172172

173-
- **Usage:**
173+
- **使用方法:**
174174

175-
Apply a mixin in the whole application scope. Once registered they can be used in the template of any component within the current application. This can be used by plugin authors to inject custom behavior into components. **Not recommended in application code**.
175+
アプリケーションスコープ全体に mixin を適用します。一度登録された場合、該当のアプリケーション内の任意のコンポーネントのテンプレートで利用することができます。プラグイン作者がコンポーネントにカスタムの振る舞いを注入するために使用することができます。**アプリケーションコードでは推奨されません。**.
176176

177-
- **See also:** [Global Mixin](../guide/mixins.html#global-mixin)
177+
- **参照:** [Global Mixin](../guide/mixins.html#global-mixin)
178178

179179
## mount
180180

181-
- **Arguments:**
181+
- **引数:**
182182

183183
- `{Element | string} rootContainer`
184184
- `{boolean} isHydrate (optional)`
185185

186-
- **Returns:**
186+
- **返り値:**
187187

188-
- The root component instance
188+
- ルートコンポーネントのインスタンス
189189

190-
- **Usage:**
190+
- **使用方法:**
191191

192-
Mounts a root component of the application instance on the provided DOM element.
192+
渡された DOM 要素に対して、アプリケーションインスタンスのルートコンポーネントをマウントします。
193193

194-
- **Example:**
194+
- **:**
195195

196196
```html
197197
<body>
@@ -203,41 +203,41 @@ Apart from `el`, you should treat these arguments as read-only and never modify
203203
import { createApp } from 'vue'
204204

205205
const app = createApp({})
206-
// do some necessary preparations
206+
// 必要な事前処理を実行
207207
app.mount('#my-app')
208208
```
209209

210-
- **See also:**
210+
- **参照:**
211211
- [Lifecycle Diagram](../guide/instance.html#lifecycle-diagram)
212212

213213
## provide
214214

215-
- **Arguments:**
215+
- **引数:**
216216

217217
- `{string | Symbol} key`
218218
- `value`
219219

220-
- **Returns:**
220+
- **返り値:**
221221

222-
- The application instance
222+
- アプリケーションのインスタンス
223223

224-
- **Usage:**
224+
- **使用方法:**
225225

226-
Sets a value that can be injected into all components within the application. Components should use `inject` to receive the provided values.
227-
228-
From a `provide`/`inject` perspective, the application can be thought of as the root-level ancestor, with the root component as its only child.
226+
アプリケーション内のすべてのコンポーネントがアクセスできる値を設定します。コンポーネントは provide されている値を受け取るためには、 `inject` を使用しなければなりません。
229227

230-
This method should not be confused with the [provide component option](options-composition.html#provide-inject) or the [provide function](composition-api.html#provide-inject) in the composition API. While those are also part of the same `provide`/`inject` mechanism, they are used to configure values provided by a component rather than an application.
228+
`provide`/`inject` の観点からはアプリケーションはルートレベルでの祖先であり、ルートコンポーネントはその子コンポーネントであると考えることができます。
231229

232-
Providing values via the application is especially useful when writing plugins, as plugins typically wouldn't be able to provide values using components. It is an alternative to using [globalProperties](application-config.html#globalproperties).
230+
このメソッドは、 Composition API の [provide コンポーネントオプション](options-composition.html#provide-inject)[provide 関数](composition-api.html#provide-inject)と混同してはいけません。これらも同じ provide/inject メカニズムの一部ですが、アプリケーションではなく、コンポーネントによって提供される値を設定するために利用されます。
231+
232+
プラグインはコンポーネントを使って値を提供することができないため、アプリケーションを通じて値を提供することは、プラグインを書くときに特に便利です。これは [globalProperties](application-config.html#globalproperties) を使用することの代替となる方法です。
233233

234234
:::tip Note
235-
The `provide` and `inject` bindings are NOT reactive. This is intentional. However, if you pass down an observed object, properties on that object do remain reactive.
235+
`provide` および `inject` のバインディングはリアクティブではありません。これは意図的な挙動です。 しかし、リアクティブなオブジェクトを設定した場合は、プロパティはリアクティブなままとなります。
236236
:::
237237

238-
- **Example:**
238+
- **:**
239239

240-
Injecting a property into the root component, with a value provided by the application:
240+
アプリケーションから提供された値を持つプロパティを、ルートコンポーネントに対して注入します:
241241

242242
```js
243243
import { createApp } from 'vue'
@@ -254,20 +254,20 @@ const app = createApp({
254254
app.provide('user', 'administrator')
255255
```
256256

257-
- **See also:**
257+
- **参照:**
258258
- [Provide / Inject](../guide/component-provide-inject.md)
259259

260260
## unmount
261261

262-
- **Arguments:**
262+
- **引数:**
263263

264264
- `{Element | string} rootContainer`
265265

266-
- **Usage:**
266+
- **使用方法:**
267267

268-
Unmounts a root component of the application instance on the provided DOM element.
268+
与えられた引数に合致した DOM 要素のアプリケーションインスタンスのルート要素をアンマウントします。
269269

270-
- **Example:**
270+
- **:**
271271

272272
```html
273273
<body>
@@ -279,30 +279,30 @@ app.provide('user', 'administrator')
279279
import { createApp } from 'vue'
280280

281281
const app = createApp({})
282-
// do some necessary preparations
282+
// 必要な事前処理を実行
283283
app.mount('#my-app')
284284

285-
// Application will be unmounted 5 seconds after mount
285+
// アプリケーションは5秒後にアンマウントされます
286286
setTimeout(() => app.unmount('#my-app'), 5000)
287287
```
288288

289289
## use
290290

291-
- **Arguments:**
291+
- **引数:**
292292

293293
- `{Object | Function} plugin`
294294
- `...options (optional)`
295295

296-
- **Returns:**
296+
- **返り値:**
297+
298+
- アプリケーションのインスタンス
297299

298-
- The application instance
300+
- **使用方法:**
299301

300-
- **Usage:**
302+
Vue.js プラグインをインストールします。プラグインが Object の場合は `install` メソッドが必要となります。関数の場合は、それ自体をインストールメソッドとして適用します。
301303

302-
Install a Vue.js plugin. If the plugin is an Object, it must expose an `install` method. If it is a function itself, it will be treated as the install method.
303-
304-
The install method will be called with the application as its first argument. Any `options` passed to `use` will be passed on in subsequent arguments.
304+
インストールメソッドはアプリケーションを第一引数に受け取って実行されます。`use` に渡されたあらゆるy `options` は、第二引数以降に渡されます。
305305

306-
When this method is called on the same plugin multiple times, the plugin will be installed only once.
306+
同じプラグインに対してこのメソッドが複数回呼び出された場合、プラグインは一度だけインストールされます。
307307

308-
- **See also:** [Plugins](../guide/plugins.html)
308+
- **参照:** [Plugins](../guide/plugins.html)

0 commit comments

Comments
 (0)