Skip to content

Commit e2c8359

Browse files
docs: small revisions to the global API migration guide (#788)
1 parent fa60703 commit e2c8359

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/guide/migration/global-api.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ badges:
55

66
# Global 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 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:
99

1010
```js
1111
Vue.component('button-counter', {
@@ -28,18 +28,18 @@ While this approach is convenient, it leads to a couple of problems. Technically
2828

2929
- 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:
3030

31-
```js
32-
import { createLocalVue, mount } from '@vue/test-utils'
31+
```js
32+
import { createLocalVue, mount } from '@vue/test-utils'
3333

34-
// create an extended `Vue` constructor
35-
const localVue = createLocalVue()
34+
// create an extended `Vue` constructor
35+
const localVue = createLocalVue()
3636

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)
3939

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+
```
4343

4444
- Global configuration makes it difficult to share the same copy of Vue between multiple "apps" on the same page, but with different global configurations.
4545

@@ -73,7 +73,7 @@ const { createApp } = Vue
7373
const app = createApp({})
7474
```
7575

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:
7777

7878
| 2.x Global API | 3.x Instance API (`app`) |
7979
| -------------------------- | ----------------------------------------------------------------------------------------------- |
@@ -103,17 +103,17 @@ This config option was introduced with the intention to support native custom el
103103
Vue.config.ignoredElements = ['my-el', /^ion-/]
104104

105105
// after
106-
const app = Vue.createApp({})
106+
const app = createApp({})
107107
app.config.isCustomElement = tag => tag.startsWith('ion-')
108108
```
109109

110110
::: tip Important
111111

112-
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).
113113

114114
- 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;
115115
- This will be a new top-level option in the Vue CLI config.
116-
:::
116+
:::
117117

118118
### `Vue.prototype` Replaced by `config.globalProperties`
119119

@@ -128,7 +128,7 @@ Vue.prototype.$http = () => {}
128128

129129
```js
130130
// after - Vue 3
131-
const app = Vue.createApp({})
131+
const app = createApp({})
132132
app.config.globalProperties.$http = () => {}
133133
```
134134

@@ -155,7 +155,7 @@ app.use(VueRouter)
155155

156156
## Mounting App Instance
157157

158-
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)`:
159159

160160
```js
161161
import { createApp } from 'vue'
@@ -219,7 +219,7 @@ import Bar from './Bar.vue'
219219

220220
const createMyApp = options => {
221221
const app = createApp(options)
222-
app.directive('focus' /* ... */)
222+
app.directive('focus', /* ... */)
223223

224224
return app
225225
}
@@ -228,4 +228,4 @@ createMyApp(Foo).mount('#foo')
228228
createMyApp(Bar).mount('#bar')
229229
```
230230

231-
Now the `focus` directive will be available in both Foo and Bar instances and their descendants.
231+
Now the `focus` directive will be available in both `Foo` and `Bar` instances and their descendants.

0 commit comments

Comments
 (0)