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
+18-18Lines changed: 18 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ badges:
5
5
6
6
# Global 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 has a number of global APIs and configurations that globally mutate Vue’s behavior. For instance, to register a global component, you would use the `Vue.component` API like this:
9
9
10
10
```js
11
11
Vue.component('button-counter', {
@@ -28,18 +28,18 @@ While this approach is convenient, it leads to a couple of problems. Technically
28
28
29
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:
30
30
31
-
```js
32
-
import { createLocalVue, mount } from'@vue/test-utils'
31
+
```js
32
+
import { createLocalVue, mount } from'@vue/test-utils'
33
33
34
-
// create an extended `Vue` constructor
35
-
constlocalVue=createLocalVue()
34
+
// create an extended `Vue` constructor
35
+
constlocalVue=createLocalVue()
36
36
37
-
// install a plugin “globally” on the “local” Vue constructor
38
-
localVue.use(MyPlugin)
37
+
// install a plugin “globally” on the “local” Vue constructor
38
+
localVue.use(MyPlugin)
39
39
40
-
// pass the `localVue` to the mount options
41
-
mount(Component, { localVue })
42
-
```
40
+
// pass the `localVue` to the mount options
41
+
mount(Component, { localVue })
42
+
```
43
43
44
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.
45
45
@@ -73,7 +73,7 @@ const { createApp } = Vue
73
73
constapp=createApp({})
74
74
```
75
75
76
-
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:
76
+
An app instance exposes a subset of the Vue 2 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 Vue 2 global APIs and their corresponding instance APIs:
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).
112
+
In Vue 3, 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).
113
113
114
114
- 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;
115
115
- This will be a new top-level option in the Vue CLI config.
116
-
:::
116
+
:::
117
117
118
118
### `Vue.prototype` Replaced by `config.globalProperties`
After being initialized with `createApp(/* options */)`, the app instance `app` can be used to mount a Vue root instance with `app.mount(domTarget)`:
158
+
After being initialized with `createApp(/* options */)`, the app instance `app` can be used to mount a root component instance with `app.mount(domTarget)`:
0 commit comments