Vue0.1的过滤代码如何添加到Vue2.0直接使用

作者:祗堂幻狼 时间:2024-05-22 10:41:57 

将Vue0.1里的过滤代码添加到Vue2.0,方法很简单,具体内容如下


var filters = {

orderBy: orderBy,
filterBy: filterBy,
limitBy: limitBy,

/**
 * Stringify value.
 *
 * @param {Number} indent
 */

json: {
 read: function read(value, indent) {
 return typeof value === 'string' ? value : JSON.stringify(value, null, Number(indent) || 2);
 },
 write: function write(value) {
 try {
  return JSON.parse(value);
 } catch (e) {
  return value;
 }
 }
},

/**
 * 'abc' => 'Abc'
 */

capitalize: function capitalize(value) {
 if (!value && value !== 0) return '';
 value = value.toString();
 return value.charAt(0).toUpperCase() + value.slice(1);
},

/**
 * 'abc' => 'ABC'
 */

uppercase: function uppercase(value) {
 return value || value === 0 ? value.toString().toUpperCase() : '';
},

/**
 * 'AbC' => 'abc'
 */

lowercase: function lowercase(value) {
 return value || value === 0 ? value.toString().toLowerCase() : '';
},

/**
 * 12345 => $12,345.00
 *
 * @param {String} sign
 */

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

/**
 * 'item' => 'items'
 *
 * @params
 * an array of strings corresponding to
 * the single, double, triple ... forms of the word to
 * be pluralized. When the number to be pluralized
 * exceeds the length of the args, it will use the last
 * entry in the array.
 *
 * e.g. ['single', 'double', 'triple', 'multiple']
 */

pluralize: function pluralize(value) {
 var args = toArray(arguments, 1);
 return args.length > 1 ? args[value % 10 - 1] || args[args.length - 1] : args[0] + (value === 1 ? '' : 's');
},

/**
 * Debounce a handler function.
 *
 * @param {Function} handler
 * @param {Number} delay = 300
 * @return {Function}
 */

debounce: function debounce(handler, delay) {
 if (!handler) return;
 if (!delay) {
 delay = 300;
 }
 return _debounce(handler, delay);
}
};

来源:http://www.cnblogs.com/hasubasora/p/7418369.html

标签:Vue0.1,Vue2.0,过滤
0
投稿

猜你喜欢

  • nditer—numpy.ndarray 多维数组的迭代操作

    2023-10-20 20:21:10
  • Pandas数据结构详细说明及如何创建Series,DataFrame对象方法

    2021-03-14 12:13:35
  • 详解Python 实现元胞自动机中的生命游戏(Game of life)

    2023-05-31 07:11:54
  • 简单介绍Python的轻便web框架Bottle

    2023-06-26 06:19:06
  • 详解Python类和对象内容

    2021-03-12 23:38:55
  • pygame库实现俄罗斯方块小游戏

    2022-09-11 10:43:37
  • python3.0 模拟用户登录,三次错误锁定的实例

    2022-07-23 01:35:48
  • 怎么样才能抓住用户?

    2008-10-20 12:10:00
  • python执行get提交的方法

    2022-08-09 01:53:12
  • 利用Python实现定时程序的方法

    2021-04-16 08:28:04
  • python opencv实现目标区域裁剪功能

    2022-07-15 19:17:56
  • 用vscode开发python的步骤详解

    2023-11-10 11:39:22
  • Python函数式编程

    2023-12-29 10:58:46
  • 网页设计趋势之:”勾引”用户的按钮

    2009-02-17 12:09:00
  • JS组件Bootstrap实现图片轮播效果

    2024-04-22 13:03:11
  • linux下安装python3和对应的pip环境教程详解

    2023-03-17 09:48:15
  • 如何利用Python和matplotlib更改纵横坐标刻度颜色

    2022-06-02 04:00:03
  • 利用PHP函数计算中英文字符串长度的方法

    2023-10-13 16:35:46
  • python实现删除列表中某个元素的3种方法

    2023-02-08 16:01:59
  • asp 删除数据并同时删除图片的代码

    2011-02-28 10:39:00
  • asp之家 网络编程 m.aspxhome.com