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
@@ -32,20 +32,20 @@ You can use the `v-else` directive to indicate an "else block" for `v-if`:
32
32
33
33
<divclass="composition-api">
34
34
35
-
[Try it in the Playground](https://sfc.vuejs.org/#eyJBcHAudnVlIjoiPHNjcmlwdCBzZXR1cD5cbmltcG9ydCB7IHJlZiB9IGZyb20gJ3Z1ZSdcblxuY29uc3QgYXdlc29tZSA9IHJlZih0cnVlKVxuPC9zY3JpcHQ+XG5cbjx0ZW1wbGF0ZT5cbiAgPGJ1dHRvbiBAY2xpY2s9XCJhd2Vzb21lID0gIWF3ZXNvbWVcIj50b2dnbGU8L2J1dHRvbj5cblxuXHQ8aDEgdi1pZj1cImF3ZXNvbWVcIj5WdWUgaXMgYXdlc29tZSE8L2gxPlxuXHQ8aDEgdi1lbHNlPk9oIG5vIPCfmKI8L2gxPlxuPC90ZW1wbGF0ZT4iLCJpbXBvcnQtbWFwLmpzb24iOiJ7XG4gIFwiaW1wb3J0c1wiOiB7XG4gICAgXCJ2dWVcIjogXCJodHRwczovL3NmYy52dWVqcy5vcmcvdnVlLnJ1bnRpbWUuZXNtLWJyb3dzZXIuanNcIlxuICB9XG59In0=)
[Try it in the Playground](https://sfc.vuejs.org/#eyJBcHAudnVlIjoiPHNjcmlwdD5cbmV4cG9ydCBkZWZhdWx0IHtcbiAgZGF0YSgpIHtcbiAgXHRyZXR1cm4ge1xuXHQgICAgYXdlc29tZTogdHJ1ZVxuICBcdH1cblx0fVxufVxuPC9zY3JpcHQ+XG5cbjx0ZW1wbGF0ZT5cbiAgPGJ1dHRvbiBAY2xpY2s9XCJhd2Vzb21lID0gIWF3ZXNvbWVcIj50b2dnbGU8L2J1dHRvbj5cblxuXHQ8aDEgdi1pZj1cImF3ZXNvbWVcIj5WdWUgaXMgYXdlc29tZSE8L2gxPlxuXHQ8aDEgdi1lbHNlPk9oIG5vIPCfmKI8L2gxPlxuPC90ZW1wbGF0ZT4iLCJpbXBvcnQtbWFwLmpzb24iOiJ7XG4gIFwiaW1wb3J0c1wiOiB7XG4gICAgXCJ2dWVcIjogXCJodHRwczovL3NmYy52dWVqcy5vcmcvdnVlLnJ1bnRpbWUuZXNtLWJyb3dzZXIuanNcIlxuICB9XG59In0=)
A `v-else`element must immediately follow a `v-if`or a `v-else-if` element - otherwise it will not be recognized.
44
+
Một phần tử `v-else`phải theo ngay sau `v-if`hoặc `v-else-if`, nếu không nó sẽ không được chấp nhận.
45
45
46
46
## `v-else-if`
47
47
48
-
The `v-else-if`, as the name suggests, serves as an "else if block" for`v-if`. It can also be chained multiple times:
48
+
Như tên gọi cho thấy, `v-else-if` đóng vai trò là một "khối else if" cho`v-if`. Ta có thể viết nhiều `v-else-if` liên tiếp nhau:
49
49
50
50
```vue-html
51
51
<div v-if="type === 'A'">
@@ -62,11 +62,11 @@ The `v-else-if`, as the name suggests, serves as an "else if block" for `v-if`.
62
62
</div>
63
63
```
64
64
65
-
Similar to`v-else`, a `v-else-if`element must immediately follow a `v-if`or a `v-else-if` element.
65
+
Tương tự`v-else`, một phần tử `v-else-if`phải theo ngay sau `v-if`hoặc `v-else-if`.
66
66
67
-
## `v-if`on`<template>`
67
+
## `v-if`trên`<template>`
68
68
69
-
Because `v-if`is a directive, it has to be attached to a single element. But what if we want to toggle more than one element? In this case we can use `v-if`on a `<template>` element, which serves as an invisible wrapper. The final rendered result will not include the `<template>` element.
69
+
Vì là một directive, `v-if`phải được gắn với một phần tử duy nhất. Nhưng nếu ta muốn kích hoạt nhiều hơn một phần tử thì sao? Trong trường hợp này, ta có thể sử dụng `v-if`trên một phần tử `<template>`, đóng vai trò như một khối bọc (wrapper) vô hình. Kết quả render cuối cùng sẽ không bao gồm phần tử `<template>`.
70
70
71
71
```vue-html
72
72
<template v-if="ok">
@@ -76,34 +76,34 @@ Because `v-if` is a directive, it has to be attached to a single element. But wh
76
76
</template>
77
77
```
78
78
79
-
`v-else`and`v-else-if`can also be used on`<template>`.
79
+
`v-else`và`v-else-if`cũng có thể sử dụng trên`<template>`.
80
80
81
81
## `v-show`
82
82
83
-
Another option for conditionally displaying an element is the `v-show` directive. The usage is largely the same:
83
+
Một lựa chọn khác cho việc render một phần tử theo điều kiện là directive `v-show`. Cách sử dụng gần như hoàn toàn tương tự:
84
84
85
85
```vue-html
86
86
<h1 v-show="ok">Hello!</h1>
87
87
```
88
88
89
-
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.
89
+
Điểm khác nhau căn bản là một phần tử với `v-show`sẽ luôn được render và nằm trong DOM; `v-show`chỉ kích hoạt thuộc tính CSS `display`của phần tử.
90
90
91
-
`v-show`doesn't support the`<template>`element, nor does it work with`v-else`.
91
+
`v-show`không hỗ trợ`<template>`và không hoạt động với`v-else`.
92
92
93
93
## `v-if` vs `v-show`
94
94
95
-
`v-if`is "real" conditional rendering because it ensures that event listeners and child components inside the conditional block are properly destroyed and re-created during toggles.
95
+
`v-if`là hiển thị có điều kiện "thật" vì nó đảm bảo các xử lý sự kiện và component con bên trong khối điều kiện bị hủy bỏ và tái tạo trong quá trình kích hoạt.
96
96
97
-
`v-if`is also **lazy**: if the condition is false on initial render, it will not do anything - the conditional block won't be rendered until the condition becomes true for the first time.
97
+
Đồng thời, `v-if`cũng **lười biếng** (lazy): nếu điều kiện trả về giá trị sai (falsy) khi hiển thị lần đầu, nó sẽ không làm gì cả - khối điều kiện sẽ không được render cho đến khi điều kiện trở thành đúng lần đầu tiên.
98
98
99
-
In comparison, `v-show`is much simpler - the element is always rendered regardless of initial condition, with CSS-based toggling.
99
+
Để so sánh, `v-show`đơn giản hơn nhiều – phần tử luôn được render bất kể điều kiện ban đầu và được kích hoạt bằng CSS.
100
100
101
-
Generally speaking, `v-if`has higher toggle costs while `v-show`has higher initial render costs. So prefer`v-show`if you need to toggle something very often, and prefer `v-if`if the condition is unlikely to change at runtime.
101
+
Nói tóm lại, `v-if`có chi phí kích hoạt cao hơn, trong khi `v-show`có chi phí render lần đầu cao hơn. Vì vậy`v-show`phù hợp nếu bạn cần kích hoạt cái gì đó thường xuyên, và `v-if`phù hợp nếu điều kiện gần như không thay đổi trong quá trình chạy (runtime).
102
102
103
103
## `v-if` with `v-for`
104
104
105
-
::: warning Note
106
-
It's **not**recommended to use `v-if`and`v-for`on the same element due to implicit precedence. Refer to [style guide](/style-guide/rules-essential.html#avoid-v-if-with-v-for)for details.
105
+
::: warning Chú ý
106
+
**Không nên**dùng `v-if`và`v-for`trên cùng một phần tử do sự ưu tiên ngầm định. Tham khảo [hướng dẫn cách viết](/style-guide/rules-essential.html#avoid-v-if-with-v-for)để biết thêm chi tiết.
107
107
:::
108
108
109
-
When `v-if`and`v-for`are both used on the same element, `v-if`will be evaluated first. See the [list rendering guide](list#v-for-with-v-if)for details.
109
+
Khi dùng cả `v-if`và`v-for`trên cùng một phần tử, `v-if`sẽ được xử lý trước. Xem [hướng dẫn về render danh sách](list#v-for-with-v-if)để biết thêm chi tiết.
0 commit comments