函数:

const digitsRE = /(\d{3})(?=\d)/g

export function currency (value, currency, decimals) {
value = parseFloat(value)
if (!isFinite(value) || (!value && value !== 0)) return ''
currency = currency != null ? currency : '$'
decimals = decimals != null ? decimals : 2
var stringified = Math.abs(value).toFixed(decimals)
var _int = decimals
? stringified.slice(0, -1 - decimals)
: stringified
var i = _int.length % 3
var head = i > 0
? (_int.slice(0, i) + (_int.length > 3 ? ',' : ''))
: ''
var _float = decimals
? stringified.slice(-1 - decimals)
: ''
var sign = value < 0 ? '-' : ''
return sign + currency + head +
_int.slice(i).replace(digitsRE, '$1,') +
_float
}

  

引入:

import {currency} from './../util/currency'

  定义局部过滤器:

  filters:{
currency:currency
},

  使用:

  <div class="item-total">
Item total: <span class="total-price">{{totalPrice|currency('$')}}</span>
</div>

  全局过滤器:在main.js

import  {currency} from './util/currency'
Vue.filter("currency",currency);

  使用:

<div class="cart-tab-4">
<div class="item-price-total">{{(item.productNum*item.salePrice)|currency('$')}}</div>
</div>

  效果:

最新文章

  1. 构建Maven聚合工程
  2. 3D打印公司网站dedecms大气模板
  3. 微信小程序开发初体验--教你开发小程序
  4. javascript函数的定义与执行
  5. 【poj2828】Buy Tickets
  6. XML的介绍
  7. 手把手教你在Windows下使用MinGW编译libav(参考libx264的编入)
  8. 【军哥谈CI框架】之入门教程之第二讲:分析CI结构和CI是怎么工作的
  9. UVA 1646 Edge Case
  10. Hibernate查询之Criteria查询
  11. WinSock IO模型 -- WSAEventSelect模型事件触发条件说明
  12. bzoj2346[Baltic 2011]Lamp
  13. IIS 部署WCF服务注意事项
  14. 第七次作业——numpy统计分布显示
  15. JIRA日期格式设置
  16. experiment 3
  17. activiti自己定义流程之整合(四):整合自己定义表单部署流程定义
  18. Unix域套接字简介
  19. 新浪微博API的使用Python
  20. 原生Ajax使用

热门文章

  1. 手写代码注意点--java.lang.Math 相关
  2. Http 请求头中 X-Requested-With 的含义
  3. [Kubernetes]CentOS7下Etcd集群搭建
  4. 应用 XAF 开发移动手机应用
  5. C++ 类中特殊的成员变量(常变量、引用、静态)的初始化方法
  6. hibernate框架学习之二级缓存
  7. python操作Excel的库openpyxl
  8. CF 313B
  9. Laravel 5.2问题-----postman进api的post请求,为什么出现Forbidden?
  10. jqGrid后台交互样例