- 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.
- C++程序設(shè)計(第3版)
- Building Modern Web Applications Using Angular
- Visual FoxPro程序設(shè)計教程
- 單片機C語言程序設(shè)計實訓(xùn)100例:基于STC8051+Proteus仿真與實戰(zhàn)
- Java面向?qū)ο蟪绦蜷_發(fā)及實戰(zhàn)
- Kotlin Standard Library Cookbook
- Python數(shù)據(jù)分析從0到1
- 深入淺出React和Redux
- Odoo 10 Implementation Cookbook
- R語言:邁向大數(shù)據(jù)之路(加強版)
- Java Web應(yīng)用開發(fā)給力起飛
- CodeIgniter Web Application Blueprints
- Android編程權(quán)威指南(第4版)
- UI動效設(shè)計從入門到精通
- 創(chuàng)新工場講AI課:從知識到實踐