Vue.filter('money', (value, symbol = '', currency = '¥', decimals = 0) => {
const digitsRE = /(\d{3})(?=\d)/g
value = parseFloat(value)
if (!isFinite(value) || (!value && value !== 0)) return ''
currency = currency != null ? currency : '$'
decimals = decimals != null ? decimals : 2
let stringified = Math.abs(value).toFixed(decimals)
let _int = decimals ?
stringified.slice(0, -1 - decimals) :
stringified
let i = _int.length % 3
let head = i > 0 ?
(_int.slice(0, i) + (_int.length > 3 ? symbol : '')) :
''
let _float = decimals ?
stringified.slice(-1 - decimals) :
''
let sign = value < 0 ? '-' : ''
return sign + currency + head +
_int.slice(i).replace(digitsRE, '$1,') +
_float
})
Vue.filter('percent', value => { // 百分比
return `${value}%`
})
Vue.filter('FormatMoney', (value, hasDecimal) => { // 千位数字以上*代替
value = parseFloat(value).toFixed(hasDecimal)
let result = '';
let b = value.split(".")
for (let i = 0; b[0].length > 3; i++) {
if (i == 0) {
result = ',' + b[0].slice(-3) + result
} else {
result = ',***' + result
}
b[0] = b[0].slice(0, b[0].length - 3)
}
if (b[0]) {
if (result.length > 0) {
for (var y = 0; b[0].length > y; y++) {
result = "*" + result
}
} else {
result = b[0] + result
}
}
if (b[1]) {
return result + '.' + b[1]
}
return result
})
Vue.filter('currency', (value, hasDecimal) => { // 数量格式化
if (hasDecimal) {
value = parseFloat(value).toFixed(hasDecimal)
}
return value && value.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1,') || 0
})
Vue.filter('time', (value, mark = '-') => {
if (!value)
return
let time = new Date(value)
return moment(time).format(`YYYY${mark}MM${mark}DD`)
})

一些filter的更多相关文章

  1. django 操作数据库--orm(object relation mapping)---models

    思想 django为使用一种新的方式,即:关系对象映射(Object Relational Mapping,简称ORM). PHP:activerecord Java:Hibernate C#:Ent ...

  2. JavaWeb——Filter

    一.基本概念 之前我们用一篇博文介绍了Servlet相关的知识,有了那篇博文的知识积淀,今天我们学习Filter将会非常轻松,因为Filter有很多地方和Servlet类似,下面在讲Filter的时候 ...

  3. 以bank account 数据为例,认识elasticsearch query 和 filter

    Elasticsearch 查询语言(Query DSL)认识(一) 一.基本认识 查询子句的行为取决于 query context filter context 也就是执行的是查询(query)还是 ...

  4. AngularJS过滤器filter-保留小数,小数点-$filter

    AngularJS      保留小数 默认是保留3位 固定的套路是 {{deom | number:4}} 意思就是保留小数点 的后四位 在渲染页面的时候 加入这儿个代码 用来精确浮点数,指定小数点 ...

  5. 挑子学习笔记:特征选择——基于假设检验的Filter方法

    转载请标明出处: http://www.cnblogs.com/tiaozistudy/p/hypothesis_testing_based_feature_selection.html Filter ...

  6. [模拟电路] 2、Passive Band Pass Filter

    note: Some articles are very good in http://www.electronics-tutorials.ws/,I share them in the Cnblog ...

  7. AngularJS过滤器filter-时间日期格式-渲染日期格式-$filter

    今天遇到了这些问题索性就 写篇文章吧 话不多说直接上栗子 不管任何是HTML格式还是JS格式必须要在  controller 里面写 // new Date() 获取当前时间 yyyy-MM-ddd ...

  8. 《ES6基础教程》之 map、forEach、filter indexOf 用法

    1,map,对数组的每个元素进行一定操作,返回一个新的数组. var oldArr = [{first_name:"Colin",last_name:"Toh" ...

  9. 1. 使用Filter 作为控制器

    最近整理一下学习笔记,并且准备放到自己的博客上.也顺便把Struts2 复习一遍 1. MVC 设计模式概览 实现 MVC(Model.View.Controller) 模式的应用程序由 3 大部分构 ...

  10. angularjs之filter过滤器

    现在公司用ionic,就是基于angularjs封装了一些api用于webapp,最近用的angularjs的filter确实省了很多代码,现在总结一下! ng比较鸡肋的过滤器,这里就一笔带过吧!鸡汤 ...

随机推荐

  1. 【BZOJ1087】[SCOI2005] 互不侵犯King(状压DP)

    点此看题面 大致题意: 在\(N×N\)的棋盘里面放\(K\)个国王,使他们互不攻击,共有多少种摆放方案(国王能攻击到它周围的8个格子). 状压\(DP\) 一看到这道题我就想到了经典的八皇后问题,但 ...

  2. 【转】iOS学习笔记(八)——iOS网络通信http之NSURLConnection

    移动互联网时代,网络通信已是手机终端必不可少的功能.我们的应用中也必不可少的使用了网络通信,增强客户端与服务器交互.这一篇提供了使用NSURLConnection实现http通信的方式. NSURLC ...

  3. 用ComboBox控件制作浏览器网址输入框

    实现效果: 知识运用: ComboBox控件的FindString public int FindString(string s) //查找数据项集合中指定数据项的索引 和Select方法 publi ...

  4. 欠采样(undersampling)和过采样(oversampling)会对模型带来怎样的影响

    项目中出现了二分类数据不平横问题,研究总结下对于类别不平横问题的处理经验: 为什么类别不平横会影响模型的输出? 许多模型的输出类别是基于阈值的,例如逻辑回归中小于0.5的为反例,大于则为正例.在数据不 ...

  5. Abode Dreamweaver cc 安装与激活

    原文链接Abode Dreamweaver CC是Adobe宣布放弃Creative Suite系列产品后推出的新版Creative Cloud产品,功能上修复了CS6中出现的选取代码不精准的问题,最 ...

  6. iView - Form中想要重置DatePicker生效,必须给DatePicker绑定value属性

    Form中想要重置DatePicker生效,必须给DatePicker绑定value属性

  7. k8s使用自定义证书将客户端认证接入到API Server

    自定义证书使用kubectl认证接入API Serverkubeconfig是API Server的客户端连入API Server时使用的认证格式的客户端配置文件.使用kubectl config v ...

  8. php 数据脱敏显示

    /** * 数据脱敏 * @param $string 需要脱敏值 * @param int $start 开始 * @param int $length 结束 * @param string $re ...

  9. PHP 批量操作 Excel

    自己封装了一个批量操作excel文件的方法,通过xls文件地址集合遍历,第三个参数传入一个匿名函数用于每个需求的不同进行的操作,实例中我想要得到列表中含有折字的行,封装成sql语句返回. xls文件超 ...

  10. centos 关闭AliYunDun

    执行命令: service aegis stop #停止服务 chkconfig --del aegis # 删除服务