- 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.
- Mastering OpenLayers 3
- 程序員面試白皮書
- Spring 5企業(yè)級(jí)開發(fā)實(shí)戰(zhàn)
- Getting started with Google Guava
- Vue.js 2 and Bootstrap 4 Web Development
- Neo4j Essentials
- TypeScript實(shí)戰(zhàn)指南
- 名師講壇:Spring實(shí)戰(zhàn)開發(fā)(Redis+SpringDataJPA+SpringMVC+SpringSecurity)
- Ext JS 4 Web Application Development Cookbook
- Spring+Spring MVC+MyBatis整合開發(fā)實(shí)戰(zhàn)
- Nginx Lua開發(fā)實(shí)戰(zhàn)
- Keras深度學(xué)習(xí)實(shí)戰(zhàn)
- Practical GIS
- Web程序設(shè)計(jì):ASP.NET(第2版)
- Building Slack Bots