- 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>
推薦閱讀
- Java程序設(shè)計(慕課版)
- Python概率統(tǒng)計
- R語言經(jīng)典實例(原書第2版)
- 小創(chuàng)客玩轉(zhuǎn)圖形化編程
- Java EE框架整合開發(fā)入門到實戰(zhàn):Spring+Spring MVC+MyBatis(微課版)
- 動手玩轉(zhuǎn)Scratch3.0編程:人工智能科創(chuàng)教育指南
- OpenCV 3和Qt5計算機視覺應(yīng)用開發(fā)
- DevOps Automation Cookbook
- 新手學(xué)Visual C# 2008程序設(shè)計
- Learning Neo4j 3.x(Second Edition)
- Unity Shader入門精要
- Mastering Rust
- Learning Hunk
- 硅谷Python工程師面試指南:數(shù)據(jù)結(jié)構(gòu)、算法與系統(tǒng)設(shè)計
- Visual Studio 2015高級編程(第6版)