Skip to content

Commit 95c9c8e

Browse files
committed
translate Migration Guide > Global API
1 parent ef9d733 commit 95c9c8e

File tree

1 file changed

+48
-48
lines changed

1 file changed

+48
-48
lines changed

src/guide/migration/global-api.md

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ badges:
33
- breaking
44
---
55

6-
# Global API <MigrationBadges :badges="$frontmatter.badges" />
6+
# グローバル API <MigrationBadges :badges="$frontmatter.badges" />
77

8-
Vue 2.x has a number of global APIs and configurations that globally mutate Vue’s behavior. For instance, to create a global component, you would use the `Vue.component` API like this:
8+
Vue 2.x では、グローバルに Vue の振る舞いを変更するグローバル API や設定が多数ありました。例えば、グローバルコンポーネントを作る際には、 以下のような `Vue.component` API を使用していました:
99

1010
```js
1111
Vue.component('button-counter', {
@@ -16,35 +16,35 @@ Vue.component('button-counter', {
1616
})
1717
```
1818

19-
Similarly, this is how a global directive is declared:
19+
同様に、以下のようにグローバルなディレクティブを宣言できました:
2020

2121
```js
2222
Vue.directive('focus', {
2323
inserted: el => el.focus()
2424
})
2525
```
2626

27-
While this approach is convenient, it leads to a couple of problems. Technically, Vue 2 doesn't have a concept of an "app". What we define as an app is simply a root Vue instance created via `new Vue()`. Every root instance created from the same Vue constructor **shares the same global configuration**. As a result:
27+
この方法は便利でしたが、いくつか問題がありました。Vue 2 では、内部的には "app" (アプリケーション) の概念がありませんでした。私達が アプリケーションとして定義していたものは、単に `new Vue()` で生成された ルート Vue インスタンス でした。同じ Vue コンストラクタから作成された root インスタンスは、**同じグローバル設定を共有します**。その結果として:
2828

29-
- Global configuration makes it easy to accidentally pollute other test cases during testing. Users need to carefully store original global configuration and restore it after each test (e.g. resetting `Vue.config.errorHandler`). Some APIs like `Vue.use` and `Vue.mixin` don't even have a way to revert their effects. This makes tests involving plugins particularly tricky. In fact, vue-test-utils has to implement a special API `createLocalVue` to deal with this:
29+
- グローバル設定を使用することで、テスト中に他のテストケースを誤って汚染しやすくなってしまいました。ユーザーは元のグローバル設定を保存し、各テスト後に元に戻すことを注意深くやる必要がありました (例 `Vue.config.errorHandler` のリセット)。`Vue.use` や、`Vue.mixin` のような API は、影響を元に戻す方法もありません。このため、プラグインを含むテストは特に厄介でした。実際、vue-test-utils はそれらに対応するために `createLocalVue` という特別な API を作らなければなりませんでした:
3030

3131
```js
3232
import { createLocalVue, mount } from '@vue/test-utils'
3333

34-
// create an extended `Vue` constructor
34+
// 拡張した `Vue` コンストラクタを作成
3535
const localVue = createLocalVue()
3636

37-
// install a plugin “globally” on the “local” Vue constructor
37+
// "ローカル" Vue コンストラクタに、"グローバル" にプラグインをインストール
3838
localVue.use(MyPlugin)
3939

40-
// pass the `localVue` to the mount options
40+
// `localVue` をマウントオプションに渡す
4141
mount(Component, { localVue })
4242
```
4343

44-
- Global configuration makes it difficult to share the same copy of Vue between multiple "apps" on the same page, but with different global configurations.
44+
- また、グローバル設定では、同じページ上の複数のアプリケーション間でグローバル設定が異なる Vue のコピーを共有することが困難でした。
4545

4646
```js
47-
// this affects both root instances
47+
// 以下は両方のルートインスタンスに影響を及ぼします
4848
Vue.mixin({
4949
/* ... */
5050
})
@@ -53,41 +53,41 @@ mount(Component, { localVue })
5353
const app2 = new Vue({ el: '#app-2' })
5454
```
5555

56-
To avoid these problems, in Vue 3 we introduce …
56+
これらの問題を回避するために、Vue 3 では、以下のような API を導入しました。
5757

58-
## A New Global API: `createApp`
58+
## 新しいグローバル API: `createApp`
5959

60-
Calling `createApp` returns an _app instance_, a new concept in Vue 3.
60+
`createApp` の呼び出しでは、 Vue 3 の新しい概念である _アプリケーションインスタンス_ を返します。
6161

6262
```js
6363
import { createApp } from 'vue'
6464

6565
const app = createApp({})
6666
```
6767

68-
An app instance exposes a subset of the current global APIs. The rule of thumb is _any APIs that globally mutate Vue's behavior are now moved to the app instance_. Here is a table of the current global APIs and their corresponding instance APIs:
68+
アプリケーションインスタンスは、現在のグローバル API のサブセットを公開します。おおまかには、_Vue の振る舞いをグローバルに変更する全ての API は、アプリケーションインスタンスに移されます_ 。こちらは、現在のグローバル API とインスタンス API との対応表です:
6969

70-
| 2.x Global API | 3.x Instance API (`app`) |
71-
| -------------------------- | ----------------------------------------------------------------------------------------------- |
72-
| Vue.config | app.config |
73-
| Vue.config.productionTip | _removed_ ([see below](#config-productiontip-removed)) |
74-
| Vue.config.ignoredElements | app.config.isCustomElement ([see below](#config-ignoredelements-is-now-config-iscustomelement)) |
75-
| Vue.component | app.component |
76-
| Vue.directive | app.directive |
77-
| Vue.mixin | app.mixin |
78-
| Vue.use | app.use ([see below](#a-note-for-plugin-authors)) |
70+
| 2.x グローバル API | 3.x インスタンス API (`app`) |
71+
| -------------------------- | ------------------------------------------------------------------------------------------------ |
72+
| Vue.config | app.config |
73+
| Vue.config.productionTip | _削除_ ([以下を参照](#config-productiontip-removed)) |
74+
| Vue.config.ignoredElements | app.config.isCustomElement ([以下を参照](#config-ignoredelements-is-now-config-iscustomelement)) |
75+
| Vue.component | app.component |
76+
| Vue.directive | app.directive |
77+
| Vue.mixin | app.mixin |
78+
| Vue.use | app.use ([以下を参照](#a-note-for-plugin-authors)) |
7979

80-
All other global APIs that do not globally mutate behavior are now named exports, as documented in [Global API Treeshaking](./global-api-treeshaking.html).
80+
グローバルに振る舞いを変更しないその他のグローバル API は [グローバル API Treeshaking](./global-api-treeshaking.html) にあるように、名前付きエクスポートになりました。
8181

82-
### `config.productionTip` Removed
82+
### `config.productionTip` の削除
8383

84-
In Vue 3.x, the "use production build" tip will only show up when using the "dev + full build" (the build that includes the runtime compiler and has warnings).
84+
Vue 3.x では "use production build" のヒントは、"dev + full build" (ランタイムコンパイラを含み、警告があるビルド) を使用しているときにのみ表示されます。
8585

86-
For ES modules builds, since they are used with bundlers, and in most cases a CLI or boilerplate would have configured the production env properly, this tip will no longer show up.
86+
ES Modules ビルドでは、モジュールバンドラーと一緒に使用されていることと、ほとんどの場合 CLI やボイラープレートで本番環境が適切に設定されているため、このヒントは表示されなくなりました。
8787

88-
### `config.ignoredElements` Is Now `config.isCustomElement`
88+
### `config.ignoredElements` `config.isCustomElement` に変更
8989

90-
This config option was introduced with the intention to support native custom elements, so the renaming better conveys what it does. The new option also expects a function which provides more flexibility than the old string / RegExp approach:
90+
この設定オプションはネイティブのカスタム要素をサポートする意図で導入されたため、それがわかるように名前に変更しました。新しいオプションでは、以前の 文字列 / RegExp の方法より、柔軟な方法を提供する関数を期待します。
9191

9292
```js
9393
// before
@@ -98,17 +98,17 @@ const app = Vue.createApp({})
9898
app.config.isCustomElement = tag => tag.startsWith('ion-')
9999
```
100100

101-
::: tip Important
101+
::: tip 重要
102102

103-
In 3.0, the check of whether an element is a component or not has been moved to the template compilation phase, therefore this config option is only respected when using the runtime compiler. If you are using the runtime-only build, `isCustomElement` must be passed to `@vue/compiler-dom` in the build setup instead - for example, via the [`compilerOptions` option in vue-loader](https://vue-loader.vuejs.org/options.html#compileroptions).
103+
Vue 3.0 では、要素がコンポーネントであるかどうかのチェックはコンパイルフェーズに移されたため、この設定はランタイムコンパイラを使用しているときにのみ尊重されます。ランタイム限定のビルドを使用している場合は、代わりにビルド設定で `isCustomElement` `@vue/compiler-dom` に渡す必要があります - 例えば [`compilerOptions` option in vue-loader](https://vue-loader.vuejs.org/options.html#compileroptions) で。
104104

105-
- If `config.isCustomElement` is assigned to when using a runtime-only build, a warning will be emitted instructing the user to pass the option in the build setup instead;
106-
- This will be a new top-level option in the Vue CLI config.
105+
- ランタイム限定ビルド使用時に、`config.isCustomElement` が代入された場合、ビルドの設定でこのオプションを設定するように警告が表示されます。
106+
- これは、Vue CLI 設定の新しいトップレベルのオプションになります。
107107
:::
108108

109-
### A Note for Plugin Authors
109+
### プラグイン作者へのノート
110110

111-
It is a common practice for plugin authors to install the plugins automatically in their UMD builds using `Vue.use`. For instance, this is how the official `vue-router` plugin installs itself in a browser environment:
111+
プラグイン作者の一般的なプラクティスとして、`Vue.use` を使ってプラグインを自動的に UMD ビルドにインストールさせるものがありました。例えば、公式の `vue-router` プラグインのブラウザ環境へのインストールは以下のようになっていました:
112112

113113
```js
114114
var inBrowser = typeof window !== 'undefined'
@@ -118,16 +118,16 @@ if (inBrowser && window.Vue) {
118118
}
119119
```
120120

121-
As the `use` global API is no longer available in Vue 3, this method will cease to work and calling `Vue.use()` will now trigger a warning. Instead, the end-user will now have to explicitly specify using the plugin on the app instance:
121+
`use` グローバル API は、Vue 3 では利用できなくなったので、このメソッドは動作しなくなり、 `Vue.use()` の呼び出しは警告が出るようになりました。その代わりに、エンドユーザーはアプリケーションのインスタンスでプラグインを使用することを明示的に指定する必要があります。
122122

123123
```js
124124
const app = createApp(MyApp)
125125
app.use(VueRouter)
126126
```
127127

128-
## Mounting App Instance
128+
## アプリケーションインスタンスのマウント
129129

130-
After being initialized with `createApp(/* options */)`, the app instance `app` can be used to mount a Vue root instance with `app.mount(domTarget)`:
130+
`createApp(/* オプション */)` で初期化した後、アプリケーションインスタンス `app` は、`app.mount(domTarget)` を使って Vue ルートインスタンスをマウントできます。
131131

132132
```js
133133
import { createApp } from 'vue'
@@ -137,7 +137,7 @@ const app = createApp(MyApp)
137137
app.mount('#app')
138138
```
139139

140-
With all these changes, the component and directive we have at the beginning of the guide will be rewritten into something like this:
140+
これらの変更によって、このガイドの初めにあるコンポーネントとディレクティブの例は以下のように書き換えられます:
141141

142142
```js
143143
const app = createApp(MyApp)
@@ -153,21 +153,21 @@ app.directive('focus', {
153153
mounted: el => el.focus()
154154
})
155155

156-
// now every application instance mounted with app.mount(), along with its
157-
// component tree, will have the same “button-counter” component
158-
// and “focus” directive without polluting the global environment
156+
// このようにして、app.mount() でマウントされた全てのアプリケーションインスタンスは、
157+
// グローバル環境を汚染すること無く、同じ "button-counter" コンポーネントと
158+
// "focus" ディレクティブを持つようになりました。
159159
app.mount('#app')
160160
```
161161

162162
## Provide / Inject
163163

164-
Similar to using the `provide` option in a 2.x root instance, a Vue 3 app instance can also provide dependencies that can be injected by any component inside the app:
164+
Vue 2.x のルートインスタンスで `provide` オプションを使用するのとどうように、Vue 3 のアプリケーションインスタンスでも、アプリケーション内の任意のコンポーネントに注入できる依存関係を提供できます:
165165

166166
```js
167-
// in the entry
167+
// エントリー
168168
app.provide('guide', 'Vue 3 Guide')
169169

170-
// in a child component
170+
// 子コンポーネント
171171
export default {
172172
inject: {
173173
book: {
@@ -178,9 +178,9 @@ export default {
178178
}
179179
```
180180

181-
## Share Configurations Among Apps
181+
## アプリケーション間での設定の共有
182182

183-
One way to share configurations e.g. components or directives among apps is to create a factory function, like this:
183+
コンポーネントや、ディレクティブの設定をアプリケーション間で共有する方法の一つとして、以下のようなファクトリ関数があります:
184184

185185
```js
186186
import { createApp } from 'vue'
@@ -198,4 +198,4 @@ createMyApp(Foo).mount('#foo')
198198
createMyApp(Bar).mount('#bar')
199199
```
200200

201-
Now the `focus` directive will be available in both Foo and Bar instances and their descendants.
201+
このようにして、 `fucus` ディレクティブは Foo Bar 両方のインスタンスとその子で有効になります。

0 commit comments

Comments
 (0)