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
The directive `v-if`is used to conditionally render a block. The block will only be rendered if the directive's expression returns a truthy value.
9
+
Instruksi `v-if`biasa digunakan untuk melakukan render sebuah blok secara bersyarat. Blok hanya akan di-*render* apabila ekspresi instruksi mengembalikan nilai benar.
10
10
11
11
```html
12
-
<h1v-if="awesome">Vue is awesome!</h1>
12
+
<h1v-if="awesome">Vue itu mengagumkan!</h1>
13
13
```
14
14
15
-
It is also possible to add an "else block" with`v-else`:
15
+
Juga memungkinkan untuk menambahkan "blok else" dengan`v-else`:
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.
24
+
Sebab`v-if`adalah sebuah instruksi, maka ia harus ditempelkan pada sebuah elemen tunggal. Tetapi bagaimana jika kita ingin beralih lebih dari satu elemen? Dalam kasus ini kita dapat menggunakan`v-if`pada sebuah elemen `<template>`, yang akan bertindak sebagai pembungkus yang tak terlihat. Hasil akhir dari *rendering* tidak akan menyertakan elemen`<template>`.
25
25
26
26
```html
27
27
<templatev-if="ok">
28
-
<h1>Title</h1>
29
-
<p>Paragraph 1</p>
30
-
<p>Paragraph 2</p>
28
+
<h1>Judul</h1>
29
+
<p>Paragraf 1</p>
30
+
<p>Paragraf 2</p>
31
31
</template>
32
32
```
33
33
34
34
### `v-else`
35
35
36
-
You can use the`v-else`directive to indicate an "else block" for`v-if`:
36
+
Anda bisa menggunakan instruksi`v-else`untuk menunjukkan sebuah "blok else" untuk`v-if`:
37
37
38
38
```html
39
39
<divv-if="Math.random() > 0.5">
40
-
Now you see me
40
+
Sekarang Anda dapat melihatku
41
41
</div>
42
42
<divv-else>
43
-
Now you don't
43
+
Sekarang tidak bisa
44
44
</div>
45
45
```
46
46
47
-
A `v-else`element must immediately follow a `v-if`or a `v-else-if`element - otherwise it will not be recognized.
47
+
Sebuah elemen `v-else`harus berada setelah `v-if`atau setelah elemen `v-else-if`- jika tidak maka ia tidak akan dikenali.
48
48
49
49
### `v-else-if`
50
50
51
-
> New in 2.1.0+
51
+
> Baru tersedia pada 2.1.0+
52
52
53
-
The `v-else-if`, as the name suggests, serves as an "else if block" for`v-if`. It can also be chained multiple times:
53
+
`v-else-if`, sesuai namanya, bertindak sebagai "blok else if" untuk`v-if`. Ia juga bisa dirangkai berkali-kali:
54
54
55
55
```html
56
56
<divv-if="type === 'A'">
@@ -63,44 +63,44 @@ The `v-else-if`, as the name suggests, serves as an "else if block" for `v-if`.
63
63
C
64
64
</div>
65
65
<divv-else>
66
-
Not A/B/C
66
+
Bukan A/B/C
67
67
</div>
68
68
```
69
69
70
-
Similar to`v-else`, a `v-else-if`element must immediately follow a `v-if`or a `v-else-if` element.
70
+
Sama seperti`v-else`, sebuah elemen `v-else-if`harus berada sesudah `v-if`atau sesudah elemen `v-else-if`.
71
71
72
-
### Controlling Reusable Elements with`key`
72
+
### Mengendalikan Elemen Reusable dengan`key`
73
73
74
-
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:
74
+
Vue mencoba me-*render* elemen se-efisien mungkin, lebih sering memakainya kembali dibandingkan melakukan *rendering* dari awal. Itulah mengapa Vue sangat cepat, dimana hal ini memiliki banyak manfaat. Sebagai contoh, jika Anda mengizinkan pengguna untuk beralih antar jenis *login*:
75
75
76
76
```html
77
77
<templatev-if="loginType === 'username'">
78
78
<label>Username</label>
79
-
<inputplaceholder="Enter your username">
79
+
<inputplaceholder="Masukkan username Anda">
80
80
</template>
81
81
<templatev-else>
82
82
<label>Email</label>
83
-
<inputplaceholder="Enter your email address">
83
+
<inputplaceholder="Masukkan alamat surel Anda">
84
84
</template>
85
85
```
86
86
87
-
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 `<input>`is not replaced - just its`placeholder`.
87
+
Kemudian peralihan `loginType`pada kode di atas tidak akan menghapus apa yang pengguna telah ketikkan. Karena templat keduanya menggunakan elemen yang sama, `<input>`tidak akan ditimpa - hanya bagian`placeholder`.
88
88
89
-
Check it out for yourself by entering some text in the input, then pressing the toggle button:
89
+
Periksa sendiri dengan memasukkan beberapa teks pada kotak isian, lalu tekan tombol alih:
<button @click="toggleLoginType">Beralih jenis login</button>
104
104
</div>
105
105
<script>
106
106
newVue({
@@ -117,7 +117,7 @@ new Vue({
117
117
</script>
118
118
{% endraw %}
119
119
120
-
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:
120
+
Hal ini kadang tidak diinginkan, sehingga Vue menawarkan cara bagi Anda yang bilang, "Dua elemen ini sepenuhnya terpisah - jangan gunakan ulang mereka." Tambahkan sebuah atribut `key`dengan nilai yang unik:
121
121
122
122
```html
123
123
<templatev-if="loginType === 'username'">
@@ -130,21 +130,21 @@ This isn't always desirable though, so Vue offers a way for you to say, "These t
130
130
</template>
131
131
```
132
132
133
-
Now those inputs will be rendered from scratch each time you toggle. See for yourself:
133
+
Sekarang kotak isian tersebut akan di-*render* dari awal tiap kali tombol alih ditekan. Bisa dilihat di bawah:
134
134
135
135
{% raw %}
136
136
<divid="key-example"class="demo">
137
137
<div>
138
138
<template v-if="loginType === 'username'">
139
139
<label>Username</label>
140
-
<input placeholder="Enter your username" key="username-input">
<button @click="toggleLoginType">Beralih jenis login</button>
148
148
</div>
149
149
<script>
150
150
newVue({
@@ -161,32 +161,32 @@ new Vue({
161
161
</script>
162
162
{% endraw %}
163
163
164
-
Note that the `<label>`elements are still efficiently re-used, because they don't have`key` attributes.
164
+
Harap diperhatikan bahwa elemen `<label>`masih digunakan ulang secara efisien, sebab tidak memiliki atribut`key`.
165
165
166
166
## `v-show`
167
167
168
-
Another option for conditionally displaying an element is the `v-show` directive. The usage is largely the same:
168
+
Opsi lain untuk menampilkan elemen secara bersyarat adalah menggunakan instruksi `v-show`. Penggunaannya kurang lebih sama:
169
169
170
170
```html
171
-
<h1v-show="ok">Hello!</h1>
171
+
<h1v-show="ok">Halo!</h1>
172
172
```
173
173
174
-
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.
174
+
Perbedaannya adalah `v-show`akan selalu melakukan *rendering* dan tetap berada di DOM; `v-show`hanya mengalihkan properti CSS `display`dari elemen tersebut.
175
175
176
-
<pclass="tip">Note that `v-show` doesn't support the `<template>` element, nor does it work with `v-else`.</p>
176
+
<pclass="tip">Sebagai catatan bahwa `v-show` tidak mendukung elemen `<template>`, begitu pula tidak bekerja dengan `v-else`.</p>
177
177
178
178
## `v-if` vs `v-show`
179
179
180
-
`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.
180
+
`v-if`merupakan rendering bersyarat yang "nyata (real)" sebab ia memastikan bahwa penyimak *event* dan komponen anak di dalam blok kondisional benar benar dihancurkan dan dibuat ulang selama peralihan.
181
181
182
-
`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.
182
+
`v-if`juga **malas**: jika kondisi bernilai salah pada render awal, maka tidak akan melakukan apa-apa - blok kondisional tidak akan di-*render* hingga kondisi menjadi bernilai benar untuk pertama kali.
183
183
184
-
In comparison, `v-show`is much simpler - the element is always rendered regardless of initial condition, with CSS-based toggling.
184
+
Sebagai perbandingan, `v-show`jauh lebih sederhana - elemen akan selalu di-*render* tak terkecuali kondisi awal, dengan melakukan peralihan berbasis CSS.
185
185
186
-
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.
186
+
Secara umum, `v-if`memiliki biaya peralihan yang lebih tinggi sementara `v-show`memiliki biaya *rendering* awal yang lebih tinggi. Jadi lebih baik gunakan `v-show`jika Anda butuh pengalihan yang cukup sering, dan gunakan`v-if` if kondisi tidak mungkin berubah saat *runtime*.
187
187
188
-
## `v-if`with`v-for`
188
+
## `v-if`dengan`v-for`
189
189
190
-
<pclass="tip">Using `v-if` and `v-for` together is **not recommended**. See the [style guide](/v2/style-guide/#Avoid-v-if-with-v-for-essential) for further information.</p>
190
+
<pclass="tip">Menggunakan `v-if` dan `v-for` secara bersama-sama **tidak direkomendasikan**. Lihat [panduan gaya](/v2/style-guide/#Avoid-v-if-with-v-for-essential) untuk informasi lebih lanjut.</p>
191
191
192
-
When used together with`v-if`, `v-for`has a higher priority than `v-if`. See the <ahref="../guide/list.html#V-for-and-v-if">list rendering guide</a> for details.
192
+
Ketika menggunakan bersama-sama dengan`v-if`, `v-for`memiliki prioritas yang lebih tinggi dibanding `v-if`. Lihat <ahref="../guide/list.html#V-for-and-v-if">panduan list rendering</a> untuk detailnya.
0 commit comments