- Vue.js 2.x by Example
- Mike Street
- 109字
- 2021-07-02 20:00:27
Format balance
Before we move on to filtering the users, add a method to correctly format the balance, prepending a currency symbol defined in the data object and ensuring there are two numbers after the decimal point. We can adapt our method from Chapter 1, Getting Started with Vue.js, to achieve this. Our Vue application should now look like this:
const app = new Vue({
el: '#app',
data: {
people: [...],
currency: '$'
},
methods: {
activeStatus(person) {
return (person.isActive) ? 'Active' : 'Inactive';
},
formatBalance(balance) {
return this.currency + balance.toFixed(2);
}
}
});
We can utilize this new method in our View:
<td>{{ formatBalance(person.balance) }}</td>
推薦閱讀
- Instant Node Package Manager
- TypeScript入門與實戰
- 體驗設計原理:行為、情感和細節
- Java應用開發與實踐
- Vue.js 3.x從入門到精通(視頻教學版)
- Implementing Cisco Networking Solutions
- Python Data Analysis(Second Edition)
- Elasticsearch for Hadoop
- Expert Data Visualization
- 數據結構習題解析與實驗指導
- INSTANT Sinatra Starter
- Practical GIS
- 數據分析與挖掘算法:Python實戰
- Python數據科學實踐指南
- ArcPy and ArcGIS(Second Edition)