Skip to content

Commit 34b160d

Browse files
mnr2ndmazipan
authored andcommitted
Terjemahan Halaman Komponen Props (vuejs#71)
* Terjemahan Komponen Props * Perbaikan Terjemahan Halaman Komponen Props vuejs#18 Mohon masukannya sekali lagi * Update terjemahan comment, mengganti "pass = memasukkan" dengan "pass = mengoper", perbaikan lainnya * kata bind/binding tidak diterjemahkan * Terjemahan comment yang ketinggalan
1 parent 1cf5791 commit 34b160d

File tree

1 file changed

+77
-77
lines changed

1 file changed

+77
-77
lines changed

src/v2/guide/components-props.md

Lines changed: 77 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ type: guide
44
order: 102
55
---
66

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.
88
9-
## Prop Casing (camelCase vs kebab-case)
9+
## Aturan Huruf Prop (camelCase vs kebab-case)
1010

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) :
1212

1313
``` js
1414
Vue.component('blog-post', {
@@ -23,17 +23,17 @@ Vue.component('blog-post', {
2323
<blog-post post-title="hello!"></blog-post>
2424
```
2525

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

28-
## Prop Types
28+
## Tipe Prop
2929

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

3232
```js
3333
props: ['title', 'likes', 'isPublished', 'commentIds', 'author']
3434
```
3535

36-
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 :
3737

3838
```js
3939
props: {
@@ -47,85 +47,85 @@ props: {
4747
}
4848
```
4949

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

52-
## Passing Static or Dynamic Props
52+
## Mengoper(*Passing*) Props Statis atau Dinamis
5353

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

5656
```html
5757
<blog-post title="My journey with Vue"></blog-post>
5858
```
5959

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

6262
```html
63-
<!-- Dynamically assign the value of a variable -->
63+
<!-- Secara dinamis menetapkan nilai dari sebuah variabel -->
6464
<blog-post v-bind:title="post.title"></blog-post>
6565

66-
<!-- Dynamically assign the value of a complex expression -->
66+
<!-- Secara dinamis menetapkan nilai dari sebuah ekspresi kompleks -->
6767
<blog-post
6868
v-bind:title="post.title + ' by ' + post.author.name"
6969
></blog-post>
7070
```
7171

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

74-
### Passing a Number
74+
### Mengoper sebuah Angka
7575

7676
```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 -->
7979
<blog-post v-bind:likes="42"></blog-post>
8080

81-
<!-- Dynamically assign to the value of a variable. -->
81+
<!-- Secara dinamis menetapkan nilai dari sebuah variabel. -->
8282
<blog-post v-bind:likes="post.likes"></blog-post>
8383
```
8484

85-
### Passing a Boolean
85+
### Mengoper sebuah Boolean
8686

8787
```html
88-
<!-- Including the prop with no value will imply `true`. -->
88+
<!-- Memuat sebuah prop yang tidak memiliki nilai akan menghasilkan nilai `true`. -->
8989
<blog-post is-published></blog-post>
9090

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 -->
9393
<blog-post v-bind:is-published="false"></blog-post>
9494

95-
<!-- Dynamically assign to the value of a variable. -->
95+
<!-- Secara dinamis menetapkan nilai dari sebuah variabel. -->
9696
<blog-post v-bind:is-published="post.isPublished"></blog-post>
9797
```
9898

99-
### Passing an Array
99+
### Mengoper sebuah Array
100100

101101
```html
102-
<!-- Even though the array is static, we need v-bind to tell Vue that -->
103-
<!-- this is a JavaScript expression rather than a string. -->
102+
<!-- Walaupun objek bersifat statis, kita perlu v-bind untuk memberi tahu Vue hal itu -->
103+
<!-- berikut ini adalah sebuah ekspresi Javascript daripada sebuah string -->
104104
<blog-post v-bind:comment-ids="[234, 266, 273]"></blog-post>
105105

106-
<!-- Dynamically assign to the value of a variable. -->
106+
<!-- Secara dinamis menetapkan nilai dari sebuah variabel. -->
107107
<blog-post v-bind:comment-ids="post.commentIds"></blog-post>
108108
```
109109

110-
### Passing an Object
110+
### Mengoper sebuah Objek
111111

112112
```html
113-
<!-- Even though the object is static, we need v-bind to tell Vue that -->
114-
<!-- this is a JavaScript expression rather than a string. -->
113+
<!-- Walaupun objek bersifat statis, kita perlu v-bind untuk memberi tahu Vue hal itu -->
114+
<!-- berikut ini adalah sebuah ekspresi Javascript daripada sebuah string -->
115115
<blog-post
116116
v-bind:author="{
117117
name: 'Veronica',
118118
company: 'Veridian Dynamics'
119119
}"
120120
></blog-post>
121121

122-
<!-- Dynamically assign to the value of a variable. -->
122+
<!-- Secara dinamis menetapkan nilai dari sebuah variabel. -->
123123
<blog-post v-bind:author="post.author"></blog-post>
124124
```
125125

126-
### Passing the Properties of an Object
126+
### Mengoper nilai Properti dari sebuah Objek
127127

128-
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`:
129129

130130
``` js
131131
post: {
@@ -134,13 +134,13 @@ post: {
134134
}
135135
```
136136

137-
The following template:
137+
Templatnya adalah sebagai berikut:
138138

139139
``` html
140140
<blog-post v-bind="post"></blog-post>
141141
```
142142

143-
Will be equivalent to:
143+
Akan menjadi sama dengan:
144144

145145
``` html
146146
<blog-post
@@ -149,15 +149,15 @@ Will be equivalent to:
149149
></blog-post>
150150
```
151151

152-
## One-Way Data Flow
152+
## Alur Data Satu-Jalur
153153

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

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

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

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

162162
``` js
163163
props: ['initialCounter'],
@@ -168,7 +168,7 @@ There are usually two cases where it's tempting to mutate a prop:
168168
}
169169
```
170170

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

173173
``` js
174174
props: ['size'],
@@ -179,41 +179,41 @@ There are usually two cases where it's tempting to mutate a prop:
179179
}
180180
```
181181

182-
<p class="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+
<p class="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>
183183

184-
## Prop Validation
184+
## Validasi Prop
185185

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

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

190190
``` js
191191
Vue.component('my-component', {
192192
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)
194194
propA: Number,
195195
// Multiple possible types
196196
propB: [String, Number],
197-
// Required string
197+
// Membutuhkan String
198198
propC: {
199199
type: String,
200200
required: true
201201
},
202-
// Number with a default value
202+
// Angka dengan sebuah nilai dasar
203203
propD: {
204204
type: Number,
205205
default: 100
206206
},
207-
// Object with a default value
207+
// Objek dengan sebuah nilai dasar
208208
propE: {
209209
type: Object,
210-
// Object or array defaults must be returned from
211-
// a factory function
210+
// Objek atau array dasar harus dikembailkan dari
211+
// sebuah factory function
212212
default: function () {
213213
return { message: 'hello' }
214214
}
215215
},
216-
// Custom validator function
216+
// Fungsi validasi yang disesuaikan
217217
propF: {
218218
validator: function (value) {
219219
// The value must match one of these strings
@@ -224,13 +224,13 @@ Vue.component('my-component', {
224224
})
225225
```
226226

227-
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).
228228

229-
<p class="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+
<p class="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>
230230

231-
### Type Checks
231+
### Pengecekan Tipe Data
232232

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

235235
- String
236236
- Number
@@ -241,7 +241,7 @@ The `type` can be one of the following native constructors:
241241
- Function
242242
- Symbol
243243

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

246246
```js
247247
function Person (firstName, lastName) {
@@ -250,7 +250,7 @@ function Person (firstName, lastName) {
250250
}
251251
```
252252

253-
You could use:
253+
Anda juga bisa menggunakan:
254254

255255
```js
256256
Vue.component('blog-post', {
@@ -260,31 +260,31 @@ Vue.component('blog-post', {
260260
})
261261
```
262262

263-
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`.
264264

265-
## Non-Prop Attributes
265+
## Atribut Non-Prop
266266

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

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

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

273273
``` html
274274
<bootstrap-date-input data-date-picker="activated"></bootstrap-date-input>
275275
```
276276

277-
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`.
278278

279-
### Replacing/Merging with Existing Attributes
279+
### Mengganti/Menyatukan dengan Atribut yang sudah ada
280280

281-
Imagine this is the template for `bootstrap-date-input`:
281+
Umpamanya ini adalah template untuk `bootstrap-date-input`:
282282

283283
``` html
284284
<input type="date" class="form-control">
285285
```
286286

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

289289
``` html
290290
<bootstrap-date-input
@@ -293,16 +293,16 @@ To specify a theme for our date picker plugin, we might need to add a specific c
293293
></bootstrap-date-input>
294294
```
295295

296-
In this case, two different values for `class` are defined:
296+
Dalam kasus ini, dua nilai yang berbeda untuk `class` didefinisikan sebagai berikut:
297297

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
300300

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`.
302302

303-
### Disabling Attribute Inheritance
303+
### Menonaktifkan Pewarisan Atribut
304304

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

307307
```js
308308
Vue.component('my-component', {
@@ -311,7 +311,7 @@ Vue.component('my-component', {
311311
})
312312
```
313313

314-
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:
315315

316316
```js
317317
{
@@ -320,7 +320,7 @@ This can be especially useful in combination with the `$attrs` instance property
320320
}
321321
```
322322

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):
324324

325325
```js
326326
Vue.component('base-input', {
@@ -339,9 +339,9 @@ Vue.component('base-input', {
339339
})
340340
```
341341

342-
<p class="tip">Note that `inheritAttrs: false` option does **not** affect `style` and `class` bindings.</p>
342+
<p class="tip">Perhatikan bahwa pengaturan `inheritAttrs: false` **tidak** mempengaruhi binding `style` dan `class`.</p>
343343

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

346346
```html
347347
<base-input

0 commit comments

Comments
 (0)