diff --git a/src/.vuepress/components/computed-1.vue b/src/.vuepress/components/computed-1.vue
deleted file mode 100644
index a9634ee11a..0000000000
--- a/src/.vuepress/components/computed-1.vue
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
Original message: "{{ message }}"
-
Computed reversed message: "{{ reversedMessage }}"
-
-
-
-
diff --git a/src/.vuepress/components/computed-2.vue b/src/.vuepress/components/computed-2.vue
deleted file mode 100644
index 2a194f208b..0000000000
--- a/src/.vuepress/components/computed-2.vue
+++ /dev/null
@@ -1,43 +0,0 @@
-
-
-
- Ask a yes/no question:
-
-
-
{{ answer }}
-
-
-
-
diff --git a/src/.vuepress/components/conditional-1.vue b/src/.vuepress/components/conditional-1.vue
deleted file mode 100644
index bcf5f3f756..0000000000
--- a/src/.vuepress/components/conditional-1.vue
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
-
-
-
diff --git a/src/.vuepress/components/conditional-2.vue b/src/.vuepress/components/conditional-2.vue
deleted file mode 100644
index 181359d4dc..0000000000
--- a/src/.vuepress/components/conditional-2.vue
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
-
-
-
diff --git a/src/.vuepress/components/intro-1.vue b/src/.vuepress/components/intro-1.vue
deleted file mode 100644
index 345d7a3eb0..0000000000
--- a/src/.vuepress/components/intro-1.vue
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
- {{ message }}
-
-
-
-
\ No newline at end of file
diff --git a/src/.vuepress/components/intro-2.vue b/src/.vuepress/components/intro-2.vue
deleted file mode 100644
index ef983df5f7..0000000000
--- a/src/.vuepress/components/intro-2.vue
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
- Hover your mouse over me for a few seconds to see my dynamically bound title!
-
-
-
-
-
\ No newline at end of file
diff --git a/src/.vuepress/components/intro-3.vue b/src/.vuepress/components/intro-3.vue
deleted file mode 100644
index 55a4082824..0000000000
--- a/src/.vuepress/components/intro-3.vue
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
- Now you see me
-
-
-
-
\ No newline at end of file
diff --git a/src/.vuepress/components/intro-4.vue b/src/.vuepress/components/intro-4.vue
deleted file mode 100644
index fdb25a851e..0000000000
--- a/src/.vuepress/components/intro-4.vue
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
- {{ todo.text }}
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/.vuepress/components/intro-5.vue b/src/.vuepress/components/intro-5.vue
deleted file mode 100644
index 398dcda010..0000000000
--- a/src/.vuepress/components/intro-5.vue
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-
{{ message }}
-
Reverse Message
-
-
-
-
\ No newline at end of file
diff --git a/src/.vuepress/components/intro-6.vue b/src/.vuepress/components/intro-6.vue
deleted file mode 100644
index 9999de0b4e..0000000000
--- a/src/.vuepress/components/intro-6.vue
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/src/.vuepress/components/intro-7.vue b/src/.vuepress/components/intro-7.vue
deleted file mode 100644
index 8c80d5fd93..0000000000
--- a/src/.vuepress/components/intro-7.vue
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-
-
-
diff --git a/src/.vuepress/components/list-1.vue b/src/.vuepress/components/list-1.vue
deleted file mode 100644
index 32b9f49884..0000000000
--- a/src/.vuepress/components/list-1.vue
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
- {{ item.message }}
-
-
-
-
-
diff --git a/src/.vuepress/components/list-2.vue b/src/.vuepress/components/list-2.vue
deleted file mode 100644
index 1230fa0b27..0000000000
--- a/src/.vuepress/components/list-2.vue
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
- {{ parentMessage }} - {{ index }} - {{ item.message }}
-
-
-
-
-
diff --git a/src/.vuepress/components/list-3.vue b/src/.vuepress/components/list-3.vue
deleted file mode 100644
index 42e3e352f8..0000000000
--- a/src/.vuepress/components/list-3.vue
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-
-
-
diff --git a/src/.vuepress/components/list-4.vue b/src/.vuepress/components/list-4.vue
deleted file mode 100644
index 4b63546434..0000000000
--- a/src/.vuepress/components/list-4.vue
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
- {{ name }}: {{ value }}
-
-
-
-
diff --git a/src/.vuepress/components/list-5.vue b/src/.vuepress/components/list-5.vue
deleted file mode 100644
index ae3e976b61..0000000000
--- a/src/.vuepress/components/list-5.vue
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-
- {{ index }}. {{ name }}: {{ value }}
-
-
-
-
-
diff --git a/src/.vuepress/components/list-6.vue b/src/.vuepress/components/list-6.vue
deleted file mode 100644
index 91d94f7471..0000000000
--- a/src/.vuepress/components/list-6.vue
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
- {{ n }}
-
-
diff --git a/src/.vuepress/components/list-7.vue b/src/.vuepress/components/list-7.vue
deleted file mode 100644
index 6857442ab6..0000000000
--- a/src/.vuepress/components/list-7.vue
+++ /dev/null
@@ -1,53 +0,0 @@
-
-
-
-
-
- {{ todo.title }}
- Remove
-
-
-
-
-
-
diff --git a/src/.vuepress/components/template-1.vue b/src/.vuepress/components/template-1.vue
deleted file mode 100644
index aa70210f26..0000000000
--- a/src/.vuepress/components/template-1.vue
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
Using mustaches: {{ rawHtml }}
-
Using v-html directive:
-
-
-
-
\ No newline at end of file
diff --git a/src/guide/class-and-style.md b/src/guide/class-and-style.md
index 7499364887..98bd3ce32b 100644
--- a/src/guide/class-and-style.md
+++ b/src/guide/class-and-style.md
@@ -123,7 +123,9 @@ However, this can be a bit verbose if you have multiple conditional classes. Tha
### With Components
-> This section assumes knowledge of [Vue Components](TODO:components.html). Feel free to skip it and come back later.
+> This section assumes knowledge of [Vue Components](component-basics.md). Feel free to skip it and come back later.
+
+> TODO: revise this with multi-root components
When you use the `class` attribute on a custom component, those classes will be added to the component's root element. Existing classes on this element will not be overwritten.
diff --git a/src/guide/computed.md b/src/guide/computed.md
index 4832972e13..8ea7070a7d 100644
--- a/src/guide/computed.md
+++ b/src/guide/computed.md
@@ -19,7 +19,7 @@ That's why for complex logic that includes reactive data, you should use a **com
### Basic Example
```html
-
+
Original message: "{{ message }}"
Computed reversed message: "{{ reversedMessage }}"
@@ -42,12 +42,17 @@ const vm = Vue.createApp({
.join('')
}
}
-}).mount('#example')
+}).mount('#computed-basic')
```
Result:
-
+
+ See the Pen
+ Computed basic example by Vue (@Vue )
+ on CodePen .
+
+
Here we have declared a computed property `reversedMessage`. The function we provided will be used as the getter function for the property `vm.reversedMessage`:
@@ -57,7 +62,7 @@ vm.message = 'Goodbye'
console.log(vm.reversedMessage) // => 'eybdooG'
```
-You can open the sandbox(TODO) and play with the example vm yourself. The value of `vm.reversedMessage` is always dependent on the value of `vm.message`.
+Try to change the value of `message` in the application `data` and you will see how `reversedMessage` is changing accordingly.
You can data-bind to computed properties in templates just like a normal property. Vue is aware that `vm.reversedMessage` depends on `vm.message`, so it will update any bindings that depend on `vm.reversedMessage` when `vm.message` changes. And the best part is that we've created this dependency relationship declaratively: the computed getter function has no side effects, which makes it easier to test and understand.
@@ -211,7 +216,7 @@ For example:
axios
.get('https://yesno.wtf/api')
.then(response => {
- this.answer = _.capitalize(response.data.answer)
+ this.answer = response.data.answer
})
.catch(error => {
this.answer = 'Error! Could not reach the API. ' + error
@@ -224,7 +229,12 @@ For example:
Result:
-
+
+ See the Pen
+ Watch basic example by Vue (@Vue )
+ on CodePen .
+
+
In this case, using the `watch` option allows us to perform an asynchronous operation (accessing an API) and sets a condition for performing this operation. None of that would be possible with a computed property.
diff --git a/src/guide/conditional.md b/src/guide/conditional.md
index bc8eaa040d..78c0962a42 100644
--- a/src/guide/conditional.md
+++ b/src/guide/conditional.md
@@ -65,46 +65,6 @@ The `v-else-if`, as the name suggests, serves as an "else if block" for `v-if`.
Similar to `v-else`, a `v-else-if` element must immediately follow a `v-if` or a `v-else-if` element.
-### Controlling Reusable Elements with `key`
-
-Vue tries to render elements as efficiently as possible, often re-using them instead of rendering from scratch. Beyond helping make Vue very fast, this can have some useful advantages. For example, if you allow users to toggle between multiple login types:
-
-```html
-
- Username
-
-
-
- Email
-
-
-```
-
-Then switching the `loginType` in the code above will not erase what the user has already entered. Since both templates use the same elements, the `
` is not replaced - just its `placeholder`.
-
-Check it out for yourself by entering some text in the input, then pressing the toggle button:
-
-
-
-This isn't always desirable though, so Vue offers a way for you to say, "These two elements are completely separate - don't re-use them." Add a `key` attribute with unique values:
-
-```html
-
- Username
-
-
-
- Email
-
-
-```
-
-Now those inputs will be rendered from scratch each time you toggle. See for yourself:
-
-
-
-Note that the `
` elements are still efficiently re-used, because they don't have `key` attributes.
-
## `v-show`
Another option for conditionally displaying an element is the `v-show` directive. The usage is largely the same:
@@ -115,9 +75,7 @@ Another option for conditionally displaying an element is the `v-show` directive
The difference is that an element with `v-show` will always be rendered and remain in the DOM; `v-show` only toggles the `display` CSS property of the element.
-::: tip
-Note that `v-show` doesn't support the ::: v-pre `` ::: element, nor does it work with `v-else`.
-:::
+`v-show` doesn't support the `` element, nor does it work with `v-else`.
## `v-if` vs `v-show`
@@ -131,7 +89,7 @@ Generally speaking, `v-if` has higher toggle costs while `v-show` has higher ini
## `v-if` with `v-for`
-::: tip
+::: tip Note
Using `v-if` and `v-for` together is **not recommended**. See the [style guide](TODO:/v2/style-guide/#Avoid-v-if-with-v-for-essential) for further information.
:::
diff --git a/src/guide/instance.md b/src/guide/instance.md
index 33dd3639bb..bd273e87f9 100644
--- a/src/guide/instance.md
+++ b/src/guide/instance.md
@@ -153,4 +153,4 @@ Don't use [arrow functions](https://developer.mozilla.org/en/docs/Web/JavaScript
Below is a diagram for the instance lifecycle. You don't need to fully understand everything going on right now, but as you learn and build more, it will be a useful reference.
-
+
diff --git a/src/guide/introduction.md b/src/guide/introduction.md
index eb55c3cf67..c0f1bb9743 100644
--- a/src/guide/introduction.md
+++ b/src/guide/introduction.md
@@ -12,13 +12,13 @@ If you are an experienced frontend developer and want to know how Vue compares t
## Getting Started
-Installation
+[Installation](installation.md)
::: tip
The official guide assumes intermediate level knowledge of HTML, CSS, and JavaScript. If you are totally new to frontend development, it might not be the best idea to jump right into a framework as your first step - grasp the basics then come back! Prior experience with other frameworks helps, but is not required.
:::
-The easiest way to try out Vue.js is using the [Hello World example](TODO). Feel free to open it in another tab and follow along as we go through some basic examples.
+The easiest way to try out Vue.js is using the [Hello World example](https://codepen.io/team/Vue/pen/KKpRVpx). Feel free to open it in another tab and follow along as we go through some basic examples.
The [Installation](installation.md) page provides more options of installing Vue. Note: We **do not** recommend that beginners start with `vue-cli`, especially if you are not yet familiar with Node.js-based build tools.
@@ -27,13 +27,13 @@ The [Installation](installation.md) page provides more options of installing Vue
At the core of Vue.js is a system that enables us to declaratively render data to the DOM using straightforward template syntax:
```html
-
+
{{ message }}
```
```js
-const App = {
+const HelloVueApp = {
data() {
return {
message: 'Hello Vue!'
@@ -41,17 +41,22 @@ const App = {
}
}
-Vue.createApp(App).mount('#app')
+Vue.createApp(HelloVueApp).mount('#hello-vue')
```
-
+We have already created our very first Vue app! This looks pretty similar to rendering a string template, but Vue has done a lot of work under the hood. The data and the DOM are now linked, and everything is now **reactive**. How do we know? Change the `message` property in the code snippet below to a different value and the rendered example will update accordingly:
-We have already created our very first Vue app! This looks pretty similar to rendering a string template, but Vue has done a lot of work under the hood. The data and the DOM are now linked, and everything is now **reactive**. How do we know? Change the `message` property in the code snippet below to a different value and the rendered example will update accordingly: 
+
+ See the Pen
+ Intro-1 by Vue (@Vue )
+ on CodePen .
+
+
In addition to text interpolation, we can also bind element attributes like this:
```html
-
+
Hover your mouse over me for a few seconds to see my dynamically bound
title!
@@ -60,7 +65,7 @@ In addition to text interpolation, we can also bind element attributes like this
```
```js
-const App2 = {
+const AttributeBindingApp = {
data() {
return {
message: 'You loaded this page on ' + new Date().toLocaleString()
@@ -68,10 +73,16 @@ const App2 = {
}
}
-Vue.createApp(App2).mount('#app-2')
+Vue.createApp(AttributeBindingApp).mount('#bind-attribute')
```
-
+
+ See the Pen
+ Attribute dynamic binding by Vue (@Vue )
+ on CodePen .
+
+
+
Here we are encountering something new. The `v-bind` attribute you are seeing is called a **directive**. Directives are prefixed with `v-` to indicate that they are special attributes provided by Vue, and as you may have guessed, they apply special reactive behavior to the rendered DOM. Here, it is basically saying "keep this element's `title` attribute up-to-date with the `message` property on the Vue instance."
## Conditionals and Loops
@@ -79,13 +90,13 @@ Here we are encountering something new. The `v-bind` attribute you are seeing is
It's easy to toggle the presence of an element, too:
```html
-
+
Now you see me
```
```js
-const App3 = {
+const ConditionalRenderingApp = {
data() {
return {
seen: true
@@ -93,19 +104,24 @@ const App3 = {
}
}
-Vue.createApp(App3).mount('#app-3')
+Vue.createApp(ConditionalRenderingApp).mount('#conditional-rendering')
```
-
-
This example demonstrates that we can bind data to not only text and attributes, but also the **structure** of the DOM. Moreover, Vue also provides a powerful transition effect system that can automatically apply [transition effects](TODO) when elements are inserted/updated/removed by Vue.
-You can change `seen` from `true` to `false` in the sandbox below to check the effect: TODO:https://codesandbox.io/s/basic-conditional-rendering-eptpp
+You can change `seen` from `true` to `false` in the sandbox below to check the effect
+
+
+ See the Pen
+ Conditional rendering by Vue (@Vue )
+ on CodePen .
+
+
There are quite a few other directives, each with its own special functionality. For example, the `v-for` directive can be used for displaying a list of items using the data from an Array:
```html
-
+
{{ todo.text }}
@@ -115,7 +131,7 @@ There are quite a few other directives, each with its own special functionality.
```
```js
-const App4 = {
+const ListRenderingApp = {
data() {
return {
todos: [
@@ -127,24 +143,29 @@ const App4 = {
}
}
-Vue.createApp(App4).mount('#app-4')
+Vue.createApp(ListRenderingApp).mount('#list-rendering')
```
-
+
+ See the Pen
+ List rendering by Vue (@Vue )
+ on CodePen .
+
+
## Handling User Input
To let users interact with your app, we can use the `v-on` directive to attach event listeners that invoke methods on our Vue instances:
```html
-
+
{{ message }}
Reverse Message
```
```js
-const App5 = {
+const EventHandlingApp = {
data() {
return {
message: 'Hello Vue.js!'
@@ -160,24 +181,29 @@ const App5 = {
}
}
-Vue.createApp(App5).mount('#app-5')
+Vue.createApp(EventHandlingApp).mount('#event-handling')
```
-
+
+ See the Pen
+ Event handling by Vue (@Vue )
+ on CodePen .
+
+
Note that in this method we update the state of our app without touching the DOM - all DOM manipulations are handled by Vue, and the code you write is focused on the underlying logic.
Vue also provides the `v-model` directive that makes two-way binding between form input and app state a breeze:
```html
-
+
```
```js
-const App6 = {
+const TwoWayBindingApp = {
data() {
return {
message: 'Hello Vue!'
@@ -185,10 +211,15 @@ const App6 = {
}
}
-Vue.createApp(App6).mount('#app-6')
+Vue.createApp(TwoWayBindingApp).mount('#two-way-binding')
```
-
+
+ See the Pen
+ Two-way binding by Vue (@Vue )
+ on CodePen .
+
+
## Composing with Components
@@ -220,7 +251,7 @@ Now you can compose it in another component's template:
```
-But this would render the same text for every todo, which is not super interesting. We should be able to pass data from the parent scope into child components. Let's modify the component definition to make it accept a [prop](TODO:components.html#Props):
+But this would render the same text for every todo, which is not super interesting. We should be able to pass data from the parent scope into child components. Let's modify the component definition to make it accept a [prop](component-basics.html#passing-data-to-child-components-with-props):
```js
app.component('todo-item', {
@@ -232,7 +263,7 @@ app.component('todo-item', {
Now we can pass the todo into each repeated component using `v-bind`:
```html
-