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
All other global APIs that do not globally mutate behavior are now named exports, as documented in [Global API Treeshaking](./global-api-treeshaking.html).
81
82
@@ -106,6 +107,25 @@ In 3.0, the check of whether an element is a component or not has been moved to
106
107
- This will be a new top-level option in the Vue CLI config.
107
108
:::
108
109
110
+
### `Vue.prototype` Replaced by `config.globalProperties`
111
+
112
+
In Vue 2, `Vue.prototype` was commonly used to add properties that would be accessible in all components.
113
+
114
+
The equivalent in Vue 3 is [`config.globalProperties`](/api/application-config.html#globalproperties). These properties will be copied across as part of instantiating a component within the application:
115
+
116
+
```js
117
+
// before - Vue 2
118
+
Vue.prototype.$http= () => {}
119
+
```
120
+
121
+
```js
122
+
// after - Vue 3
123
+
constapp=Vue.createApp({})
124
+
app.config.globalProperties.$http= () => {}
125
+
```
126
+
127
+
Using `provide` (discussed [below](#provide-inject)) should also be considered as an alternative to `globalProperties`.
128
+
109
129
### A Note for Plugin Authors
110
130
111
131
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:
@@ -178,6 +198,8 @@ export default {
178
198
}
179
199
```
180
200
201
+
Using `provide` is especially useful when writing a plugin, as an alternative to `globalProperties`.
202
+
181
203
## Share Configurations Among Apps
182
204
183
205
One way to share configurations e.g. components or directives among apps is to create a factory function, like this:
0 commit comments