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/essentials/application.md
+21-43Lines changed: 21 additions & 43 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Creating a Vue Application
2
2
3
-
## The App Instance
3
+
## The application instance
4
4
5
5
Every Vue application starts by creating a new **application instance** with the [`createApp`](/api/application#createapp) function:
6
6
@@ -32,62 +32,36 @@ While many examples in this guide only need a single component, most real applic
32
32
App (root component)
33
33
├─ TodoList
34
34
│ └─ TodoItem
35
-
│ ├─ DeleteTodoButton
36
-
│ └─ EditTodoButton
37
-
└─ TodoListFooter
38
-
├─ ClearTodosButton
39
-
└─ TodoListStatistics
35
+
│ ├─ TodoDeleteButton
36
+
│ └─ TodoEditButton
37
+
└─ TodoFooter
38
+
├─ TodoClearButton
39
+
└─ TodoStatistics
40
40
```
41
41
42
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.
43
43
44
44
## App Configurations
45
45
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:
46
+
The application 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
47
48
48
```js
49
49
app.config.errorHandler= (err) => {
50
50
/* handle error */
51
51
}
52
52
```
53
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:
You can browse the full list of app instance methods in the[API reference](/api/application).
60
+
This makes the `TodoDeleteButton` available for use anywhere in our app. We will discuss registration for components and other types of assets in later sections of the guide. You can also browse the full list of application instance APIs in its[API reference](/api/application).
87
61
88
62
## Mounting the App
89
63
90
-
An app instance won't render anything until its `.mount()` method is called.
64
+
An application instance won't render anything until its `.mount()` method is called.
91
65
It expects a "container" argument, which can either be an actual DOM element or a selector string:
92
66
93
67
```html
@@ -100,7 +74,7 @@ app.mount('#app')
100
74
101
75
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
76
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.
77
+
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 application instance.
104
78
105
79
### In-DOM Root Component Template
106
80
@@ -128,16 +102,20 @@ app.mount('#app')
128
102
129
103
Vue will automatically use the container's `innerHTML` as the template if the root component does not already have a `template` option.
130
104
131
-
## Multiple App Instances
105
+
## Multiple application instances
132
106
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:
107
+
You are not limited to a single application 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
108
135
109
```js
136
-
constapp1=createApp({ /* ... */ })
110
+
constapp1=createApp({
111
+
/* ... */
112
+
})
137
113
app1.mount('#container-1')
138
114
139
-
constapp2=createApp({ /* ... */ })
115
+
constapp2=createApp({
116
+
/* ... */
117
+
})
140
118
app2.mount('#container-2')
141
119
```
142
120
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.
121
+
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 application instance on the entire page. Instead, create multiple small application instances and mount them on the elements they are responsible for.
Copy file name to clipboardExpand all lines: src/guide/essentials/template-syntax.md
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -115,15 +115,17 @@ Each binding can only contain **one single expression**, so the following will *
115
115
116
116
### Calling Functions
117
117
118
-
It is possible to call a component-exposed method inside a binding expression. As we'll see shortly, it's usually better to use a [computed property](computed.html) instead. However, using a function call can be useful in scenarios where computed properties aren't a viable option:
118
+
It is possible to call a component-exposed method inside a binding expression:
119
119
120
120
```vue-html
121
121
<span :title="toTitleDate(date)">
122
122
{{ formatDate(date) }}
123
123
</span>
124
124
```
125
125
126
-
Functions called inside binding expressions should **not** have any side effects, such as changing data or triggering asynchronous operations. If you find yourself tempted to do that you should probably use a [lifecycle hook](/guide/essentials/lifecycle.html) instead.
126
+
:::tip
127
+
Functions called inside binding expressions will be called every time the component updates, so they should **not** have any side effects, such as changing data or triggering asynchronous operations.
128
+
:::
127
129
128
130
### Restricted Globals Access
129
131
@@ -208,8 +210,6 @@ Dynamic argument expressions have some syntax constraints because certain charac
208
210
<a :['foo' + bar]="value"> ... </a>
209
211
```
210
212
211
-
We recommend replacing any complex expressions with a [computed property](computed.html), one of the most fundamental pieces of Vue, which we'll cover shortly.
212
-
213
213
When using in-DOM templates (templates directly written in an HTML file), you should also avoid naming keys with uppercase characters, as browsers will coerce attribute names into lowercase:
Copy file name to clipboardExpand all lines: src/guide/introduction.md
+9-10Lines changed: 9 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ footer: false
9
9
10
10
Vue (pronounced /vjuː/, like **view**) is a JavaScript framework for building user interfaces. It builds on top of standard HTML, CSS and JavaScript, and provides a declarative and component-based programming model that helps you efficiently develop user interfaces, be it simple or complex.
The above example demonstrates the two core features of Vue:
@@ -73,7 +71,7 @@ Despite the flexibility, the core knowledge about how Vue works is shared across
73
71
74
72
## Single-File Components
75
73
76
-
In most build-tool-enabled Vue projects, we author Vue components using an HTML-like file format called **Single-File Component** (also known as `*.vue` files, abbreviated as **SFC**). A Vue SFC, as the name suggests, encapsulates the component's logic (JavaScript), template (HTML), and styles (CSS) in a single file. Here's the previous counter example, written in SFC format:
74
+
In most build-tool-enabled Vue projects, we author Vue components using an HTML-like file format called **Single-File Component** (also known as `*.vue` files, abbreviated as **SFC**). A Vue SFC, as the name suggests, encapsulates the component's logic (JavaScript), template (HTML), and styles (CSS) in a single file. Here's the previous example, written in SFC format:
<button @click="increment">count is: {{ count }}</button>
170
+
<button @click="increment">
171
+
Count is: {{ count }}
172
+
</button>
174
173
</template>
175
174
```
176
175
@@ -188,7 +187,7 @@ You can learn more about the comparison between the two styles and the potential
188
187
189
188
If you are new to Vue, here's our general recommendation:
190
189
191
-
- For learning purposes, go with the style that looks easier to understand to you. Again, most of the core concepts are shared between the two styles. Once you are familiar with one of them, the other one can be easily picked up.
190
+
- For learning purposes, go with the style that looks easier to understand to you. Again, most of the core concepts are shared between the two styles. You can always pick up the other one at a later time.
0 commit comments