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: .github/contributing/writing-guide.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -57,7 +57,7 @@ Writing documentation is an exercise in empathy. We're not describing an objecti
57
57
58
58
-**Avoid abbreviations** in writing and code examples (e.g. `attribute` is better than `attr`, `message` is better than `msg`), unless you are specifically referencing an abbreviation in an API (e.g. `$attrs`). Abbreviation symbols included on standard keyboards (e.g. `@`, `#`, `&`) are OK.
59
59
-**When referencing a directly following example, use a colon (`:`) to end a sentence**, rather than a period (`.`).
60
-
-**Use the Oxford comma** (e.g. "a, b, and c" instead of "a, b and c"). 
60
+
-**Use the Oxford comma** (e.g. "a, b, and c" instead of "a, b and c"). 
61
61
- Source: [The Serial (Oxford) Comma: When and Why To Use It](https://www.inkonhand.com/2015/10/the-serial-oxford-comma-when-and-why-to-use-it/)
62
62
-**When referencing the name of a project, use the name that project refers to itself as.** For example, "webpack" and "npm" should both use lowercase as that's how their documentation refers to them.
63
63
-**Use Title Case for headings** - at least for now, since it's what we use through the rest of the docs. There's research suggesting that sentence case (only first word of the heading starts with a capital) is actually superior for legibility and also reduces the cognitive overhead for documentation writers, since they don't have to try to remember whether to capitalize words like "and", "with", and "about".
Copy file name to clipboardExpand all lines: src/api/application.md
+5-2Lines changed: 5 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,9 @@
2
2
3
3
## createApp()
4
4
5
+
// TODO rework this
6
+
// TODO document that you can pass props to the root component
7
+
5
8
In Vue 3, APIs that globally mutate Vue's behavior are now moved to application instances created by the new `createApp` method. In addition, their effects are now scoped to that specific application's instance:
6
9
7
10
```js
@@ -347,7 +350,7 @@ You can modify its properties, listed below, before mounting your application.
Copy file name to clipboardExpand all lines: src/api/built-in-directives.md
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -259,6 +259,8 @@
259
259
260
260
When used without an argument, can be used to bind an object containing attribute name-value pairs. Note in this mode `class` and `style` does not support Array or Objects.
Copy file name to clipboardExpand all lines: src/guide/essentials/application.md
+98-8Lines changed: 98 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
## The App Instance
4
4
5
-
Every Vue application starts by creating a new **application instance** with the `createApp` function:
5
+
Every Vue application starts by creating a new **application instance** with the [`createApp`](/api/application#createapp) function:
6
6
7
7
```js
8
8
import { createApp } from'vue'
@@ -14,11 +14,48 @@ const app = createApp({
14
14
15
15
## The Root Component
16
16
17
-
## Mounting the App
17
+
The object we are passing into `createApp` is in fact a component. Every app requires a "root component" that can contain other components as its children.
18
+
19
+
If you are using Single File Components, we typically import the root component from another file:
20
+
21
+
```js
22
+
import { createApp } from'vue'
23
+
// import the root component App from a single-file component.
24
+
importAppfrom'./App.vue'
25
+
26
+
constapp=createApp(App)
27
+
```
28
+
29
+
While many examples in this guide only need a single component, most real applications are organized into a tree of nested, reusable components. For example, a Todo application's component tree might look like this:
30
+
31
+
```
32
+
App (root component)
33
+
├─ TodoList
34
+
│ └─ TodoItem
35
+
│ ├─ DeleteTodoButton
36
+
│ └─ EditTodoButton
37
+
└─ TodoListFooter
38
+
├─ ClearTodosButton
39
+
└─ TodoListStatistics
40
+
```
41
+
42
+
We will discuss how to define and compose multiple components together in later sections of the guide. Before that, we will focus on what happens inside a single component.
18
43
19
-
## App-Scoped Assets
44
+
## App Configurations
20
45
21
-
The application instance is used to register 'globals' that can then be used by components within that application. We'll discuss that in detail later in the guide but as a quick example:
46
+
The app instance exposes a `.config` object that allows us to configure a few app-level options, for example defining an app-level error handler that captures errors from all descendent components:
47
+
48
+
```js
49
+
app.config.errorHandler= (err) => {
50
+
/* handle error */
51
+
}
52
+
```
53
+
54
+
You can browse the full list of `app.config` options in the [API reference](/api/application#app-config).
55
+
56
+
## Global Assets
57
+
58
+
The app instance is used to register "global assets" that can then be used by components within that app. We'll discuss them in detail later in the guide but here is a quick example:
22
59
23
60
```js
24
61
constapp=createApp({})
@@ -36,9 +73,7 @@ app.provide('store', myStore)
36
73
app.use(LocalePlugin)
37
74
```
38
75
39
-
### Chaining
40
-
41
-
Most of the methods exposed by the application instance return that same instance, allowing for chaining:
76
+
Most of the methods exposed by the application instance return that same instance, so we can also use the chaining syntax:
42
77
43
78
```js
44
79
constapp=createApp({})
@@ -48,6 +83,61 @@ const app = createApp({})
48
83
.use(LocalePlugin)
49
84
```
50
85
51
-
You can browse the full application API in the [API reference](/api/application.html).
86
+
You can browse the full list of app instance methods in the [API reference](/api/application).
87
+
88
+
## Mounting the App
89
+
90
+
An app instance won't render anything until its `.mount()` method is called.
91
+
It expects a "container" argument, which can either be an actual DOM element or a selector string:
92
+
93
+
```html
94
+
<divid="app"></div>
95
+
```
96
+
97
+
```js
98
+
app.mount('#app')
99
+
```
100
+
101
+
The content of the app's root component will be rendered inside the container element. The container element itself is not considered part of the app.
102
+
103
+
The `.mount()` method should always be called after all app configurations and asset registrations are done. Also note that its return value, unlike the asset registration methods, is the root component instance instead of the app instance.
104
+
105
+
### In-DOM Root Component Template
106
+
107
+
When using Vue without a build step, we can write our root component's template directly inside the mount container:
108
+
109
+
```html
110
+
<divid="app">
111
+
<button@click="count++">{{ count }}</button>
112
+
</div>
113
+
```
114
+
115
+
```js
116
+
import { createApp } from'vue'
117
+
118
+
constapp=createApp({
119
+
data() {
120
+
return {
121
+
count:0
122
+
}
123
+
}
124
+
})
125
+
126
+
app.mount('#app')
127
+
```
128
+
129
+
Vue will automatically use the container's `innerHTML` as the template if the root component does not already have a `template` option.
52
130
53
131
## Multiple App Instances
132
+
133
+
You are not limited to a single app instance on the same page. The `createApp` API allows multiple Vue applications to co-exist on the same page, each with its own scope for configuration and global assets:
134
+
135
+
```js
136
+
constapp1=createApp({ /* ... */ })
137
+
app1.mount('#container-1')
138
+
139
+
constapp2=createApp({ /* ... */ })
140
+
app2.mount('#container-2')
141
+
```
142
+
143
+
If you are using Vue to enhance server-rendered HTML and only need Vue to control specific parts of a large page, avoid mounting a singe Vue app instance on the entire page. Instead, create multiple small app instances and mount them on the elements they are responsible for.
0 commit comments