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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

祗堂幻狼   2021-03-29 我要评论
想了解Vue0.1的过滤代码怎样添加到Vue2.0直接使用的相关内容吗,祗堂幻狼在本文为您仔细讲解Vue0.1过滤代码添加到Vue2.0用的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:Vue0.1,Vue2.0,过滤,下面大家一起来学习吧。

将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);
 }
 };

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们