You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/guide/migration/global-api.md
+48-48Lines changed: 48 additions & 48 deletions
Original file line number
Diff line number
Diff line change
@@ -3,9 +3,9 @@ badges:
3
3
- breaking
4
4
---
5
5
6
-
# Global API <MigrationBadges:badges="$frontmatter.badges" />
6
+
# グローバル API <MigrationBadges:badges="$frontmatter.badges" />
7
7
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 を使用していました:
Similarly, this is how a global directive is declared:
19
+
同様に、以下のようにグローバルなディレクティブを宣言できました:
20
20
21
21
```js
22
22
Vue.directive('focus', {
23
23
inserted:el=>el.focus()
24
24
})
25
25
```
26
26
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:
-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 を作らなければなりませんでした:
30
30
31
31
```js
32
32
import { createLocalVue, mount } from'@vue/test-utils'
33
33
34
-
//create an extended `Vue` constructor
34
+
//拡張した `Vue` コンストラクタを作成
35
35
constlocalVue=createLocalVue()
36
36
37
-
//install a plugin “globally” on the “local” Vue constructor
37
+
//"ローカル" Vue コンストラクタに、"グローバル" にプラグインをインストール
38
38
localVue.use(MyPlugin)
39
39
40
-
//pass the `localVue` to the mount options
40
+
// `localVue` をマウントオプションに渡す
41
41
mount(Component, { localVue })
42
42
```
43
43
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.
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 との対応表です:
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) にあるように、名前付きエクスポートになりました。
81
81
82
-
### `config.productionTip`Removed
82
+
### `config.productionTip`の削除
83
83
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" (ランタイムコンパイラを含み、警告があるビルド) を使用しているときにのみ表示されます。
85
85
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 やボイラープレートで本番環境が適切に設定されているため、このヒントは表示されなくなりました。
87
87
88
-
### `config.ignoredElements`Is Now `config.isCustomElement`
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:
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).
-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.
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:
@@ -118,16 +118,16 @@ if (inBrowser && window.Vue) {
118
118
}
119
119
```
120
120
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()`の呼び出しは警告が出るようになりました。その代わりに、エンドユーザーはアプリケーションのインスタンスでプラグインを使用することを明示的に指定する必要があります。
122
122
123
123
```js
124
124
constapp=createApp(MyApp)
125
125
app.use(VueRouter)
126
126
```
127
127
128
-
## Mounting App Instance
128
+
## アプリケーションインスタンスのマウント
129
129
130
-
After being initialized with `createApp(/* options */)`, the app instance `app`can be used to mount a Vue root instance with `app.mount(domTarget)`:
//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" ディレクティブを持つようになりました。
159
159
app.mount('#app')
160
160
```
161
161
162
162
## Provide / Inject
163
163
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:
0 commit comments