- 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>
推薦閱讀
- 在最好的年紀學Python:小學生趣味編程
- Kubernetes實戰
- Linux C/C++服務器開發實踐
- Python自然語言處理(微課版)
- Webpack實戰:入門、進階與調優
- Troubleshooting Citrix XenApp?
- Arduino可穿戴設備開發
- ABAQUS6.14中文版有限元分析與實例詳解
- 實戰Python網絡爬蟲
- 算法超簡單:趣味游戲帶你輕松入門與實踐
- Clojure編程樂趣
- Tkinter GUI Programming by Example
- R語言與網站分析
- React Native -Building Mobile Apps with JavaScript
- Python輕松學:爬蟲、游戲與架站