Skip to content

Commit 57abed8

Browse files
committed
revise based on feedback
1 parent a64607c commit 57abed8

File tree

3 files changed

+34
-57
lines changed

3 files changed

+34
-57
lines changed

src/guide/essentials/application.md

Lines changed: 21 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Creating a Vue Application
22

3-
## The App Instance
3+
## The application instance
44

55
Every Vue application starts by creating a new **application instance** with the [`createApp`](/api/application#createapp) function:
66

@@ -32,62 +32,36 @@ While many examples in this guide only need a single component, most real applic
3232
App (root component)
3333
├─ TodoList
3434
│ └─ TodoItem
35-
│ ├─ DeleteTodoButton
36-
│ └─ EditTodoButton
37-
└─ TodoListFooter
38-
├─ ClearTodosButton
39-
└─ TodoListStatistics
35+
│ ├─ TodoDeleteButton
36+
│ └─ TodoEditButton
37+
└─ TodoFooter
38+
├─ TodoClearButton
39+
└─ TodoStatistics
4040
```
4141

4242
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.
4343

4444
## App Configurations
4545

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

4848
```js
4949
app.config.errorHandler = (err) => {
5050
/* handle error */
5151
}
5252
```
5353

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:
59-
60-
```js
61-
const app = createApp({})
62-
63-
// register a global component
64-
app.component('SearchInput', SearchInputComponent)
65-
66-
// register a global custom directive
67-
app.directive('focus', FocusDirective)
68-
69-
// app-wide dependency injection
70-
app.provide('store', myStore)
71-
72-
// register a plugin
73-
app.use(LocalePlugin)
74-
```
75-
76-
Most of the methods exposed by the application instance return that same instance, so we can also use the chaining syntax:
54+
The application instance also provides a few methods for registering app-scoped assets. for example, registering a component:
7755

7856
```js
79-
const app = createApp({})
80-
.component('SearchInput', SearchInputComponent)
81-
.directive('focus', FocusDirective)
82-
.provide('store', myStore)
83-
.use(LocalePlugin)
57+
app.component('TodoDeleteButton', TodoDeleteButton)
8458
```
8559

86-
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).
8761

8862
## Mounting the App
8963

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.
9165
It expects a "container" argument, which can either be an actual DOM element or a selector string:
9266

9367
```html
@@ -100,7 +74,7 @@ app.mount('#app')
10074

10175
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.
10276

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.
10478

10579
### In-DOM Root Component Template
10680

@@ -128,16 +102,20 @@ app.mount('#app')
128102

129103
Vue will automatically use the container's `innerHTML` as the template if the root component does not already have a `template` option.
130104

131-
## Multiple App Instances
105+
## Multiple application instances
132106

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

135109
```js
136-
const app1 = createApp({ /* ... */ })
110+
const app1 = createApp({
111+
/* ... */
112+
})
137113
app1.mount('#container-1')
138114

139-
const app2 = createApp({ /* ... */ })
115+
const app2 = createApp({
116+
/* ... */
117+
})
140118
app2.mount('#container-2')
141119
```
142120

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.

src/guide/essentials/template-syntax.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,17 @@ Each binding can only contain **one single expression**, so the following will *
115115

116116
### Calling Functions
117117

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

120120
```vue-html
121121
<span :title="toTitleDate(date)">
122122
{{ formatDate(date) }}
123123
</span>
124124
```
125125

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+
:::
127129

128130
### Restricted Globals Access
129131

@@ -208,8 +210,6 @@ Dynamic argument expressions have some syntax constraints because certain charac
208210
<a :['foo' + bar]="value"> ... </a>
209211
```
210212

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-
213213
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:
214214

215215
```vue-html

src/guide/introduction.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ footer: false
99

1010
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.
1111

12-
Here is a minimal Vue counter example:
12+
Here is a minimal example:
1313

1414
```js
1515
import { createApp } from 'vue'
@@ -26,9 +26,8 @@ createApp({
2626
```vue-html
2727
<div id="app">
2828
<button @click="count++">
29-
Clicked {{ count }} time{{ count === 1 ? '' : 's' }}.
29+
Count is: {{ count }}
3030
</button>
31-
<button @click="count = 0">Reset</button>
3231
</div>
3332
```
3433

@@ -41,9 +40,8 @@ const count = ref(0)
4140

4241
<div class="demo">
4342
<button @click="count++">
44-
Clicked {{ count }} time{{ count === 1 ? '' : 's' }}.
43+
Count is: {{ count }}
4544
</button>
46-
<button @click="count = 0">Reset</button>
4745
</div>
4846

4947
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
7371

7472
## Single-File Components
7573

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

7876
```vue
7977
<script>
@@ -88,9 +86,8 @@ export default {
8886
8987
<template>
9088
<button @click="count++">
91-
Clicked {{ count }} time{{ count === 1 ? '' : 's' }}.
89+
Count is: {{ count }}
9290
</button>
93-
<button @click="count = 0">Reset</button>
9491
</template>
9592
9693
<style scoped>
@@ -170,7 +167,9 @@ onMounted(() => {
170167
</script>
171168
172169
<template>
173-
<button @click="increment">count is: {{ count }}</button>
170+
<button @click="increment">
171+
Count is: {{ count }}
172+
</button>
174173
</template>
175174
```
176175

@@ -188,7 +187,7 @@ You can learn more about the comparison between the two styles and the potential
188187

189188
If you are new to Vue, here's our general recommendation:
190189

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.
192191

193192
- For production use:
194193

0 commit comments

Comments
 (0)