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/api/global-api.md
+20-6
Original file line number
Diff line number
Diff line change
@@ -4,12 +4,26 @@ sidebarDepth: 1
4
4
5
5
# Global API
6
6
7
+
If you're using a CDN build then the functions of the global API are accessible via the global `Vue` object. e.g.:
8
+
9
+
```js
10
+
const { createApp, h, nextTick } = Vue
11
+
```
12
+
13
+
If you're using ES modules then they can be imported directly:
14
+
15
+
```js
16
+
import { createApp, h, nextTick } from'vue'
17
+
```
18
+
19
+
Global functions that handle reactivity, such as `reactive` and `ref`, are documented separately. See [Reactivity API](/api/reactivity-api.html) for those functions.
20
+
7
21
## createApp
8
22
9
23
Returns an application instance which provides an application context. The entire component tree mounted by the application instance share the same context.
10
24
11
25
```js
12
-
constapp=Vue.createApp({})
26
+
constapp=createApp({})
13
27
```
14
28
15
29
You can chain other methods after `createApp`, they can be found in [Application API](./application-api.html)
@@ -19,7 +33,7 @@ You can chain other methods after `createApp`, they can be found in [Application
19
33
The function receives a root component options object as a first parameter:
20
34
21
35
```js
22
-
constapp=Vue.createApp({
36
+
constapp=createApp({
23
37
data() {
24
38
return {
25
39
...
@@ -34,7 +48,7 @@ const app = Vue.createApp({
34
48
With the second parameter, we can pass root props to the application:
35
49
36
50
```js
37
-
constapp=Vue.createApp(
51
+
constapp=createApp(
38
52
{
39
53
props: ['username']
40
54
},
@@ -68,7 +82,7 @@ Returns a returns "virtual node", usually abbreviated to **VNode**: a plain obje
68
82
69
83
```js
70
84
render() {
71
-
returnVue.h('h1', {}, 'Some title')
85
+
return h('h1', {}, 'Some title')
72
86
}
73
87
```
74
88
@@ -231,7 +245,7 @@ Allows resolving a `component` by its name, if it is available in the current ap
231
245
Returns a `Component` or `undefined` when not found.
232
246
233
247
```js
234
-
constapp=Vue.createApp({})
248
+
constapp=createApp({})
235
249
app.component('MyComponent', {
236
250
/* ... */
237
251
})
@@ -296,7 +310,7 @@ Allows resolving a `directive` by its name, if it is available in the current ap
296
310
Returns a `Directive` or `undefined` when not found.
Copy file name to clipboardExpand all lines: src/api/instance-methods.md
+6-6
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@
20
20
-**Example:**
21
21
22
22
```js
23
-
constapp=Vue.createApp({
23
+
constapp=createApp({
24
24
data() {
25
25
return {
26
26
a:1,
@@ -62,7 +62,7 @@
62
62
When watched value is an object or array, any changes to its properties or elements won't trigger the watcher because they reference the same object/array:
63
63
64
64
```js
65
-
constapp=Vue.createApp({
65
+
constapp=createApp({
66
66
data() {
67
67
return {
68
68
article: {
@@ -104,7 +104,7 @@
104
104
`$watch` returns an unwatch function that stops firing the callback:
Copy file name to clipboardExpand all lines: src/api/options-lifecycle-hooks.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -42,7 +42,7 @@ All lifecycle hooks automatically have their `this` context bound to the instanc
42
42
43
43
-**Details:**
44
44
45
-
Called after the instance has been mounted, where element, passed to `Vue.createApp({}).mount()` is replaced by the newly created `vm.$el`. If the root instance is mounted to an in-document element, `vm.$el` will also be in-document when `mounted` is called.
45
+
Called after the instance has been mounted, where element, passed to [`app.mount`](/api/application-api.html#mount) is replaced by the newly created `vm.$el`. If the root instance is mounted to an in-document element, `vm.$el` will also be in-document when `mounted` is called.
46
46
47
47
Note that `mounted` does **not** guarantee that all child components have also been mounted. If you want to wait until the entire view has been rendered, you can use [vm.$nextTick](../api/instance-methods.html#nexttick) inside of `mounted`:
48
48
@@ -186,7 +186,7 @@ All lifecycle hooks automatically have their `this` context bound to the instanc
186
186
```
187
187
188
188
```js
189
-
constapp=Vue.createApp({
189
+
constapp=createApp({
190
190
data() {
191
191
return {
192
192
cart:0
@@ -232,7 +232,7 @@ All lifecycle hooks automatically have their `this` context bound to the instanc
Copy file name to clipboardExpand all lines: src/api/options-misc.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@
6
6
7
7
-**Details:**
8
8
9
-
Allow the component to recursively invoke itself in its template. Note that when a component is registered globally with `Vue.createApp({}).component({})`, the global ID is automatically set as its name.
9
+
Allow the component to recursively invoke itself in its template. Note that when a component is registered globally with [`app.component`](/api/application-api.html#component), the global ID is automatically set as its name.
10
10
11
11
Another benefit of specifying a `name` option is debugging. Named components result in more helpful warning messages. Also, when inspecting an app in the [vue-devtools](https://github.com/vuejs/vue-devtools), unnamed components will show up as `<AnonymousComponent>`, which isn't very informative. By providing the `name` option, you will get a much more informative component tree.
12
12
@@ -27,7 +27,7 @@
27
27
-**Example:**
28
28
29
29
```js
30
-
Vue.createApp({
30
+
createApp({
31
31
// Delimiters changed to ES6 template string style
0 commit comments