官术网_书友最值得收藏!

  • 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 1Getting 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>
主站蜘蛛池模板: 宾阳县| 凉城县| 乡城县| 扬中市| 辉南县| 仙居县| 寿阳县| 漠河县| 安徽省| 革吉县| 临桂县| 扎兰屯市| 体育| 肥城市| 五原县| 周宁县| 和静县| 古蔺县| 额尔古纳市| 萝北县| 榆林市| 增城市| 建瓯市| 蓝山县| 碌曲县| 板桥市| 循化| 湾仔区| 丽水市| 富锦市| 当涂县| 九龙城区| 泽普县| 获嘉县| 缙云县| 五常市| 厦门市| 金川县| 镇巴县| 英德市| 镇远县|