diff --git a/src/v2/guide/filters.md b/src/v2/guide/filters.md index 4a6eecdbf2..a0c8a4d8a8 100644 --- a/src/v2/guide/filters.md +++ b/src/v2/guide/filters.md @@ -1,20 +1,20 @@ --- -title: Filters +title: Filter type: guide order: 305 --- -Vue.js allows you to define filters that can be used to apply common text formatting. Filters are usable in two places: **mustache interpolations and `v-bind` expressions** (the latter supported in 2.1.0+). Filters should be appended to the end of the JavaScript expression, denoted by the "pipe" symbol: +Di Vue.js Anda dapat mendeklarasikan atau membuat kustom filter yang dapat digunakan untuk memformat teks. Filter digunakan dalam dua tempat: **mustache interpolations** dan ekspresi `v-bind` (didukung pada versi 2.1.0+). Filter harus ditambahkan pada bagian akhir atau setelahnya dengan menggunakan ekspresi JavaScript, dipisahkan dengan simbol "pipe" ( | ): ``` html - + {{ message | capitalize }} - +
``` -You can define local filters in a component's options: +Anda dapat mendeklarasikan filter ke dalam opsi komponen. ``` js filters: { @@ -26,7 +26,7 @@ filters: { } ``` -or define a filter globally before creating the Vue instance: +atau mendeklarasikan global filter sebelum membuat *instance* Vue: ``` js Vue.filter('capitalize', function (value) { @@ -35,12 +35,13 @@ Vue.filter('capitalize', function (value) { return value.charAt(0).toUpperCase() + value.slice(1) }) +// Vue Instance new Vue({ // ... }) ``` -Below is an example of our `capitalize` filter being used: +Di bawah ini contoh dari filter huruf kapital (`capitalize`) yang digunakan: {% raw %}
@@ -66,20 +67,21 @@ Below is an example of our `capitalize` filter being used: {% endraw %} -The filter's function always receives the expression's value (the result of the former chain) as its first argument. In the above example, the `capitalize` filter function will receive the value of `message` as its argument. +*Function* atau *method* filter selalu menerima nilai dari ekspresi nilai (hasil rantai pertama) sebagai argumen/parameter awal. Pada contoh di atas, filter dari fungsi `capitalize` akan menerima nilai dari `message` sebagai argumen-nya. -Filters can be chained: +Filter dapat dijadikan berantai (metode *chain*): ``` html {{ message | filterA | filterB }} ``` -In this case, `filterA`, defined with a single argument, will receive the value of `message`, and then the `filterB` function will be called with the result of `filterA` passed into `filterB`'s single argument. +Dalam hal ini, `filterA` yang dideklarasikan dengan satu argumen, akan menerima nilai dari `message`. Selanjutnya fungsi `filterB` akan dipanggil dengan hasil dari fungsi `filterA` yang dimasukkan ke dalam +`filterB` sebagai argumen tunggal. -Filters are JavaScript functions, therefore they can take arguments: +Karena filter merupakan *fungsi* atau *method Javascript*, maka dapat digunakan lebih dari satu argumen atau parameter. ``` html {{ message | filterA('arg1', arg2) }} ``` -Here `filterA` is defined as a function taking three arguments. The value of `message` will be passed into the first argument. The plain string `'arg1'` will be passed into the `filterA` as its second argument, and the value of expression `arg2` will be evaluated and passed in as the third argument. +Di sini `filterA` dideklarasikan sebagai sebuah fungsi yang memiliki tiga buah argumen. Nilai atau *value* dari `message` akan dimasukkan ke dalam argumen pertama. Variabel bertipe string dari `'arg1'` akan dimasukkan ke dalam `filterA` sebagai argumen kedua, dan nilai dari ekspresi `arg2` akan dievaluasi dan dimasukkan sebagai parameter ketiga.