- Vue.js 2.x by Example
- Mike Street
- 176字
- 2021-07-02 20:00:29
Passing in a second variable
The alternative to the preceding autodetection is to pass the second variable into the format function. This gives us greater flexibility and scalability should we wish to format other fields. With the second variable, we can either pass in a fixed string that matches a preselected list in our switch statement or we could pass in the field itself. An example of the fixed string approach in the view would be:
{{ format(person.balance, 'currency') }}
This would work perfectly and would be great if we had several different fields that all needed to be formatted like balance currently does, but there seems to be some slight repetition in using the balance key and currency format.
As a compromise, we are going to pass the person object as the first parameter, so we can access all the data, and the name of the field as the second parameter. We will then use this for both identifying the format method required and to return the specific data.
- Learn ECMAScript(Second Edition)
- 圖解Java數據結構與算法(微課視頻版)
- 編寫高質量代碼:改善Python程序的91個建議
- Hands-On Microservices with Kotlin
- Webpack實戰:入門、進階與調優
- Web前端應用開發技術
- Couchbase Essentials
- MySQL程序員面試筆試寶典
- Unity 2018 Augmented Reality Projects
- .NET 4.5 Parallel Extensions Cookbook
- C++從入門到精通(第6版)
- Moodle 3 Administration(Third Edition)
- AutoCAD基礎教程
- INSTANT Premium Drupal Themes
- Spring Web Services 2 Cookbook