Vue0.1的过滤代码如何添加到Vue2.0直接使用
程序员文章站
2022-09-08 20:49:32
将vue0.1里的过滤代码添加到vue2.0,方法很简单,具体内容如下
var filters = {
orderby: orderby,
filte...
将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); } };
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。