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/v2/guide/components-props.md
+77-77Lines changed: 77 additions & 77 deletions
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,11 @@ type: guide
4
4
order: 102
5
5
---
6
6
7
-
> This page assumes you've already read the [Components Basics](components.html). Read that first if you are new to components.
7
+
> Halaman ini berasumsi Anda telah membaca [dasar-dasar komponen](components.html). Baca halaman itu terlebih dahulu bila Anda belum mengerti komponen.
8
8
9
-
## Prop Casing (camelCase vs kebab-case)
9
+
## Aturan Huruf Prop (camelCase vs kebab-case)
10
10
11
-
HTML attribute names are case-insensitive, so browsers will interpret any uppercase characters as lowercase. That means when you're using in-DOM templates, camelCased prop names need to use their kebab-cased (hyphen-delimited) equivalents:
11
+
Nama atribut dalam HTML bersifat *case-insensitive*, jadi peramban akan mengartikan semua karakter yang berhuruf besar sebagai karakter yang berhuruf kecil. Itu berarti ketika Anda menggunakan templat di dalam DOM, nama prop yang berformat camelCase perlu menggunakan padanan format kebab-case (dipisahkan dengan tanda hubung) :
12
12
13
13
```js
14
14
Vue.component('blog-post', {
@@ -23,17 +23,17 @@ Vue.component('blog-post', {
23
23
<blog-postpost-title="hello!"></blog-post>
24
24
```
25
25
26
-
Again, if you're using string templates, this limitation does not apply.
26
+
Dan lagi, jika Anda menggunakan templat string, maka batasan ini tidak berlaku.
27
27
28
-
## Prop Types
28
+
## Tipe Prop
29
29
30
-
So far, we've only seen props listed as an array of strings:
30
+
Sejauh ini, kita hanya melihat props yang terdaftar sebagai sebuah string di dalam array:
Usually though, you'll want every prop to be a specific type of value. In these cases, you can list props as an object, where the properties' names and values contain the prop names and types, respectively:
36
+
Namun biasanya, Anda ingin setiap prop memiliki nilai yang spesifik tipenya. Dalam kasus ini, Anda bisa membuat daftar props sebagai sebuah objek, dimana properti nama akan berisi nama dari props sedangkan properti nilai akan berisi tipe data dari props tersebut :
37
37
38
38
```js
39
39
props: {
@@ -47,85 +47,85 @@ props: {
47
47
}
48
48
```
49
49
50
-
This not only documents your component, but will also warn users in the browser's JavaScript console if they pass the wrong type. You'll learn much more about [type checks and other prop validations](#Prop-Validation)further down this page.
50
+
Hal ini tidak hanya akan mendokumentasikan komponen Anda, tapi juga akan memperingatkan pengguna di konsol Javascript sebuah peramban jika mereka mengoper tipe data yang salah. Anda akan lebih banyak belajar tentang [pengecekan tipe data dan validasi prop lainnya](#Prop-Validation)lebih lanjut di halaman ini.
51
51
52
-
## Passing Static or Dynamic Props
52
+
## Mengoper(*Passing*) Props Statis atau Dinamis
53
53
54
-
So far, you've seen props passed a static value, like in:
54
+
Sejauh ini, Anda telah melihat props yang dimasukkan dengan sebuah nilai statis, seperti berikut:
55
55
56
56
```html
57
57
<blog-posttitle="My journey with Vue"></blog-post>
58
58
```
59
59
60
-
You've also seen props assigned dynamically with `v-bind`, such as in:
60
+
Anda juga telah melihat props yang secara dinamis ditetapkan dengan `v-bind`, seperti berikut:
61
61
62
62
```html
63
-
<!--Dynamically assign the value of a variable-->
63
+
<!--Secara dinamis menetapkan nilai dari sebuah variabel-->
64
64
<blog-postv-bind:title="post.title"></blog-post>
65
65
66
-
<!--Dynamically assign the value of a complex expression-->
66
+
<!--Secara dinamis menetapkan nilai dari sebuah ekspresi kompleks-->
67
67
<blog-post
68
68
v-bind:title="post.title + ' by ' + post.author.name"
69
69
></blog-post>
70
70
```
71
71
72
-
In the two examples above, we happen to pass string values, but _any_ type of value can actually be passed to a prop.
72
+
Dari dua contoh di atas, kita telah mengoper nilai string, tapi sebenarnya _semua_ tipe nilai dapat dimasukkan ke dalam sebuah prop.
73
73
74
-
### Passing a Number
74
+
### Mengoper sebuah Angka
75
75
76
76
```html
77
-
<!--Even though `42` is static, we need v-bind to tell Vue that-->
78
-
<!--this is a JavaScript expression rather than a string. -->
77
+
<!--Walaupun objek bersifat statis, kita perlu v-bind untuk memberi tahu Vue hal itu-->
78
+
<!--berikut ini adalah sebuah ekspresi Javascript daripada sebuah string -->
79
79
<blog-postv-bind:likes="42"></blog-post>
80
80
81
-
<!--Dynamically assign to the value of a variable. -->
81
+
<!--Secara dinamis menetapkan nilai dari sebuah variabel. -->
82
82
<blog-postv-bind:likes="post.likes"></blog-post>
83
83
```
84
84
85
-
### Passing a Boolean
85
+
### Mengoper sebuah Boolean
86
86
87
87
```html
88
-
<!--Including the prop with no value will imply `true`. -->
88
+
<!--Memuat sebuah prop yang tidak memiliki nilai akan menghasilkan nilai `true`. -->
89
89
<blog-postis-published></blog-post>
90
90
91
-
<!--Even though `false` is static, we need v-bind to tell Vue that-->
92
-
<!--this is a JavaScript expression rather than a string. -->
91
+
<!--Walaupun objek bersifat statis, kita perlu v-bind untuk memberi tahu Vue hal itu-->
92
+
<!--berikut ini adalah sebuah ekspresi Javascript daripada sebuah string -->
If you want to pass all the properties of an object as props, you can use`v-bind`without an argument (`v-bind`instead of`v-bind:prop-name`). For example, given a `post` object:
128
+
Jika Anda ingin mengoper semua nilai properti dari sebuah objek sebagai props, Anda dapat menggunakan`v-bind`tanpa sebuah argumen (`v-bind`sebagai ganti`v-bind:prop-name`). Misalnya, sebuah objek ditaruh dalam `post`:
129
129
130
130
```js
131
131
post: {
@@ -134,13 +134,13 @@ post: {
134
134
}
135
135
```
136
136
137
-
The following template:
137
+
Templatnya adalah sebagai berikut:
138
138
139
139
```html
140
140
<blog-postv-bind="post"></blog-post>
141
141
```
142
142
143
-
Will be equivalent to:
143
+
Akan menjadi sama dengan:
144
144
145
145
```html
146
146
<blog-post
@@ -149,15 +149,15 @@ Will be equivalent to:
149
149
></blog-post>
150
150
```
151
151
152
-
## One-Way Data Flow
152
+
## Alur Data Satu-Jalur
153
153
154
-
All props form a**one-way-down binding**between the child property and the parent one: when the parent property updates, it will flow down to the child, but not the other way around. This prevents child components from accidentally mutating the parent's state, which can make your app's data flow harder to understand.
154
+
Semua props berasal dari**binding satu-jalur-menurun(one-way-down)**di antara properti anak dan induknya: ketika Properti induk diperbarui, maka itu akan mengalir turun ke anak, namun tidak sebaliknya. Hal ini mencegah komponen anak secara tidak sengaja memutasi keadaan induknya, yang mana dapat membuat aplikasi Anda lebih sulit untuk dipahami.
155
155
156
-
In addition, every time the parent component is updated, all props in the child component will be refreshed with the latest value. This means you should **not**attempt to mutate a prop inside a child component. If you do, Vue will warn you in the console.
156
+
Selain itu, setiap saat komponen induk diperbarui, maka semua props yang ada di dalam komponen anak akan diperbarui dengan nilai yang terbaru. Ini berarti Anda **tidak**boleh mencoba memutasi sebuah prop di dalam komponen anak. Jika Anda melakukannya, Vue akan memperingatkan Anda dalam konsol.
157
157
158
-
There are usually two cases where it's tempting to mutate a prop:
158
+
Biasanya ada dua kasus dimana itu menggoda untuk memutasi sebuah prop:
159
159
160
-
1.**The prop is used to pass in an initial value; the child component wants to use it as a local data property afterwards.**In this case, it's best to define a local data property that uses the prop as its initial value:
160
+
1.**Prop dipakai untuk mengoper sebuah nilai awal; kemudian komponen anak ingin menggunakannya sebagai properti data lokal.**Dalam hal ini, cara yang terbaik adalah mendefinisikan properti data lokal yang menggunakan prop sebagai nilai awalnya:
161
161
162
162
```js
163
163
props: ['initialCounter'],
@@ -168,7 +168,7 @@ There are usually two cases where it's tempting to mutate a prop:
168
168
}
169
169
```
170
170
171
-
2.**The prop is passed in as a raw value that needs to be transformed.**In this case, it's best to define a computed property using the prop's value:
171
+
2.**Prop ditetapkan sebagai sebuah data mentah yang perlu untuk diubah.**Dalam kasus ini, cara yang terbaik adalah mendefiniskan sebuah properti computed dengan menggunakan nilai dari prop.
172
172
173
173
```js
174
174
props: ['size'],
@@ -179,41 +179,41 @@ There are usually two cases where it's tempting to mutate a prop:
179
179
}
180
180
```
181
181
182
-
<pclass="tip">Note that objects and arrays in JavaScript are passed by reference, so if the prop is an array or object, mutating the object or array itself inside the child component **will** affect parent state.</p>
182
+
<pclass="tip">Perhatikan bahwa objek dan array dalam Javascript ditetapkan berdasarkan referensi, jadi jika prop adalah sebuah array atau objek, memutasi objek atau array itu sendiri di dalam komponen anak **akan** mempengaruhi keadaan induk.</p>
183
183
184
-
## Prop Validation
184
+
## Validasi Prop
185
185
186
-
Components can specify requirements for its props, such as the types you've already seen. If a requirement isn't met, Vue will warn you in the browser's JavaScript console. This is especially useful when developing a component that's intended to be used by others.
186
+
Komponen dapat menentukan persyaratan untuk prop miliknya, seperti tipe yang pernah Anda lihat. Jika suatu persyaratan tidak terpenuhi, Vue akan memperingatkan Anda di konsol Javascript Peramban. Hal ini sangat berguna terutama saat pengembangan sebuah komponen yang ditujukan untuk dipakai oleh orang lain.
187
187
188
-
To specify prop validations, you can provide an object with validation requirements to the value of `props`, instead of an array of strings. For example:
188
+
Untuk menentukan validasi props, Anda dapat membuat sebuah objek dengan syarat-syarat validasi ke dalam nilai `props`, daripada hanya sebuah string di dalam array. sebagai contoh:
189
189
190
190
```js
191
191
Vue.component('my-component', {
192
192
props: {
193
-
//Basic type check (`null` and `undefined` values will pass any type validation)
193
+
//Pengecekan dasar (nilai `null` dan `undefinied` akan diloloskan oleh semua tipe validasi)
When prop validation fails, Vue will produce a console warning (if using the development build).
227
+
Jika validasi prop gagal, Vue akan membuat sebuah pesan peringatan di konsol (Jika menggunakan development build).
228
228
229
-
<pclass="tip">Note that props are validated **before** a component instance is created, so instance properties (e.g. `data`, `computed`, etc) will not be available inside `default` or `validator` functions.</p>
229
+
<pclass="tip">Perhatikan bahwa props telah divalidasi **sebelum** sebuah komponen instance dibuat, jadi properti instance (misalnya `data`, `computed`, dll) tidak akan bisa dipakai di fungsi `default` atau `validator`</p>
230
230
231
-
### Type Checks
231
+
### Pengecekan Tipe Data
232
232
233
-
The `type` can be one of the following native constructors:
233
+
Sebuah `tipe` bisa jadi adalah salah satu dari konstruktor-konstruktor asli sebagai berikut:
234
234
235
235
- String
236
236
- Number
@@ -241,7 +241,7 @@ The `type` can be one of the following native constructors:
241
241
- Function
242
242
- Symbol
243
243
244
-
In addition, `type` can also be a custom constructor function and the assertion will be made with an `instanceof` check. For example, given the following constructor function exists:
244
+
Selain itu, sebuah `tipe` bisa juga merupakan sebuah fungsi konstruktor yang disesuaikan dan pernyataannya akan dibuat dengan pemeriksaan `instanceof`. Sebagai contoh, berikut ada sebuah konstruktor:
245
245
246
246
```js
247
247
functionPerson (firstName, lastName) {
@@ -250,7 +250,7 @@ function Person (firstName, lastName) {
to validate that the value of the `author`prop was created with`new Person`.
263
+
untuk memvalidasi bahwa nilai dari prop `author`dibuat dengan`new Person`.
264
264
265
-
## Non-Prop Attributes
265
+
## Atribut Non-Prop
266
266
267
-
A non-prop attribute is an attribute that is passed to a component, but does not have a corresponding prop defined.
267
+
Sebuah atribut non-prop merupakan sebuah atribut yang telah dimasukkan ke dalam sebuah component, tapi tidak memiliki prop yang didefiniskan dengan sesuai.
268
268
269
-
While explicitly defined props are preferred for passing information to a child component, authors of component libraries can't always foresee the contexts in which their components might be used. That's why components can accept arbitrary attributes, which are added to the component's root element.
269
+
Sementara props yang telah didefinisikan secara eksplisit lebih diutamakan untuk mengoper informasi ke dalam komponen anak, pembuat pustaka komponen tidak dapat selalu melihat konteks dimana saja komponen milik mereka bisa digunakan. Itulah sebabnya komponen dapat menerima atribut semaunya, yang mana ditambahkan ke elemen komponen root.
270
270
271
-
For example, imagine we're using a 3rd-party `bootstrap-date-input`component with a Bootstrap plugin that requires a `data-date-picker`attribute on the `input`. We can add this attribute to our component instance:
271
+
Sebagai contoh, seumpama kita menggunakan komponen pihak ketiga `bootstrap-date-input`dengan sebuah plugin Bootstrap yang membutuhkan atribut `data-date-picker`di dalam `input`. Kita bisa menambahkan atribut ini ke dalam komponen instance kita :
And the`data-date-picker="activated"`attribute will automatically be added to the root element of`bootstrap-date-input`.
277
+
Dan atribut`data-date-picker="activated"`akan secara otomatis ditambahkan ke dalam elemen root dari`bootstrap-date-input`.
278
278
279
-
### Replacing/Merging with Existing Attributes
279
+
### Mengganti/Menyatukan dengan Atribut yang sudah ada
280
280
281
-
Imagine this is the template for`bootstrap-date-input`:
281
+
Umpamanya ini adalah template untuk`bootstrap-date-input`:
282
282
283
283
```html
284
284
<inputtype="date"class="form-control">
285
285
```
286
286
287
-
To specify a theme for our date picker plugin, we might need to add a specific class, like this:
287
+
Untuk menentukan sebuah tema untuk plugin date picker kita, kita perlu menambah class yang spesifik, seperti ini :
288
288
289
289
```html
290
290
<bootstrap-date-input
@@ -293,16 +293,16 @@ To specify a theme for our date picker plugin, we might need to add a specific c
293
293
></bootstrap-date-input>
294
294
```
295
295
296
-
In this case, two different values for `class`are defined:
296
+
Dalam kasus ini, dua nilai yang berbeda untuk `class`didefinisikan sebagai berikut:
297
297
298
-
-`form-control`, which is set by the component in its template
299
-
-`date-picker-theme-dark`, which is passed to the component by its parent
298
+
-`form-control`, dimana diatur oleh komponen dalam templatnya
299
+
-`date-picker-theme-dark`, dimana dimasukkan ke komponen oleh induknya
300
300
301
-
For most attributes, the value provided to the component will replace the value set by the component. So for example, passing`type="text"`will replace`type="date"`and probably break it! Fortunately, the`class`and `style`attributes are a little smarter, so both values are merged, making the final value: `form-control date-picker-theme-dark`.
301
+
Untuk sebagian besar atribut, nilai yang diberikan ke komponen akan menggantikan nilai yang ditetapkan oleh komponen. Jadi misalnya, mengoper`type =" text"`akan menggantikan`type =" date"`dan mungkin merusaknya! Untungnya, atribut`class`dan`style`sedikit lebih pintar, sehingga ketika kedua nilai digabungkan, akan membuat nilai akhir: `form-control date-picker-theme-dark`.
302
302
303
-
### Disabling Attribute Inheritance
303
+
### Menonaktifkan Pewarisan Atribut
304
304
305
-
If you do **not**want the root element of a component to inherit attributes, you can set`inheritAttrs:false`in the component's options. For example:
305
+
Jika Anda **tidak**ingin elemen root dari sebuah komponen mewariskan atribut, Anda dapat mengatur`inheritAttrs:false`di dalam pengaturan komponen. Misalnya:
This can be especially useful in combination with the `$attrs` instance property, which contains the attribute names and values passed to a component, such as:
314
+
Hal ini bisa sangat berguna dalam kombinasi dengan properti instance `$attrs`, yang mana berisikan nama dan nilai atribut yang telah dimasukkan ke sebuah komponen, seperti:
315
315
316
316
```js
317
317
{
@@ -320,7 +320,7 @@ This can be especially useful in combination with the `$attrs` instance property
320
320
}
321
321
```
322
322
323
-
With`inheritAttrs: false`and`$attrs`, you can manually decide which element you want to forward attributes to, which is often desirable for [base components](../style-guide/#Base-component-names-strongly-recommended):
323
+
Dengan`inheritAttrs: false`dan`$attrs`, Anda secara manual dapat memutuskan elemen mana yang Anda ingin teruskan ke atribut, yang mana sering diperlukan sekali untuk [dasar-dasar komponen](../style-guide/#Base-component-names-strongly-recommended):
324
324
325
325
```js
326
326
Vue.component('base-input', {
@@ -339,9 +339,9 @@ Vue.component('base-input', {
339
339
})
340
340
```
341
341
342
-
<pclass="tip">Note that `inheritAttrs: false` option does **not** affect `style` and `class` bindings.</p>
342
+
<pclass="tip">Perhatikan bahwa pengaturan `inheritAttrs: false` **tidak** mempengaruhi binding `style` dan `class`.</p>
343
343
344
-
This pattern allows you to use base components more like raw HTML elements, without having to care about which element is actually at its root:
344
+
Pola ini membolehkan Anda untuk menggunakan komponen-komponen dasar seperti elemen HTML mentah, tanpa harus peduli elemen mana yang sebenarnya berada di root:
0 commit comments