• 在Vue1.0里面的过滤代码。添加到Vue2.0用,过滤货币,大小写,筛选!


    直接上代码

      1   var filters = {
      2 
      3     orderBy: orderBy,
      4     filterBy: filterBy,
      5     limitBy: limitBy,
      6 
      7     /**
      8      * Stringify value.
      9      *
     10      * @param {Number} indent
     11      */
     12 
     13     json: {
     14       read: function read(value, indent) {
     15         return typeof value === 'string' ? value : JSON.stringify(value, null, Number(indent) || 2);
     16       },
     17       write: function write(value) {
     18         try {
     19           return JSON.parse(value);
     20         } catch (e) {
     21           return value;
     22         }
     23       }
     24     },
     25 
     26     /**
     27      * 'abc' => 'Abc'
     28      */
     29 
     30     capitalize: function capitalize(value) {
     31       if (!value && value !== 0) return '';
     32       value = value.toString();
     33       return value.charAt(0).toUpperCase() + value.slice(1);
     34     },
     35 
     36     /**
     37      * 'abc' => 'ABC'
     38      */
     39 
     40     uppercase: function uppercase(value) {
     41       return value || value === 0 ? value.toString().toUpperCase() : '';
     42     },
     43 
     44     /**
     45      * 'AbC' => 'abc'
     46      */
     47 
     48     lowercase: function lowercase(value) {
     49       return value || value === 0 ? value.toString().toLowerCase() : '';
     50     },
     51 
     52     /**
     53      * 12345 => $12,345.00
     54      *
     55      * @param {String} sign
     56      */
     57 
     58     currency: function currency(value, _currency) {
     59       value = parseFloat(value);
     60       if (!isFinite(value) || !value && value !== 0) return '';
     61       _currency = _currency != null ? _currency : '$';
     62       var stringified = Math.abs(value).toFixed(2);
     63       var _int = stringified.slice(0, -3);
     64       var i = _int.length % 3;
     65       var head = i > 0 ? _int.slice(0, i) + (_int.length > 3 ? ',' : '') : '';
     66       var _float = stringified.slice(-3);
     67       var sign = value < 0 ? '-' : '';
     68       return sign + _currency + head + _int.slice(i).replace(digitsRE, '$1,') + _float;
     69     },
     70 
     71     /**
     72      * 'item' => 'items'
     73      *
     74      * @params
     75      *  an array of strings corresponding to
     76      *  the single, double, triple ... forms of the word to
     77      *  be pluralized. When the number to be pluralized
     78      *  exceeds the length of the args, it will use the last
     79      *  entry in the array.
     80      *
     81      *  e.g. ['single', 'double', 'triple', 'multiple']
     82      */
     83 
     84     pluralize: function pluralize(value) {
     85       var args = toArray(arguments, 1);
     86       return args.length > 1 ? args[value % 10 - 1] || args[args.length - 1] : args[0] + (value === 1 ? '' : 's');
     87     },
     88 
     89     /**
     90      * Debounce a handler function.
     91      *
     92      * @param {Function} handler
     93      * @param {Number} delay = 300
     94      * @return {Function}
     95      */
     96 
     97     debounce: function debounce(handler, delay) {
     98       if (!handler) return;
     99       if (!delay) {
    100         delay = 300;
    101       }
    102       return _debounce(handler, delay);
    103     }
    104   };
  • 相关阅读:
    Postgresql主从流复制+Redis集群部署
    数据仓库实时数据同步方案
    数据库与WEB服务器的配置
    HOSTS文件
    Android 命令设置获取、IP地址、网关、dns
    转:mysqld与mysqld_safe的区别
    mysql 5.7 创建用户报错ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default value
    MySql 5.7中添加用户,新建数据库,用户授权,删除用户,修改密码
    监控网卡设备流量
    获取进程所有信息
  • 原文地址:https://www.cnblogs.com/hasubasora/p/7418369.html
Copyright © 2020-2023  润新知