Vue0.1的過濾代碼如何添加到Vue2.0直接使用
更新時間:2017年08月23日 15:36:33 作者:祗堂幻狼
Vue0.1的過濾代碼如何添加到Vue2.0直接使用,這篇文章主要介紹了過濾代碼添加到Vue2.0用的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
將Vue0.1里的過濾代碼添加到Vue2.0,方法很簡單,具體內(nèi)容如下
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);
}
};
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Vue.js實現(xiàn)一個自定義分頁組件vue-paginaiton
這篇文章主要為大家詳細介紹了Vue.js實現(xiàn)一個自定義分頁組件vue-paginaiton的具體代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-09-09
vue項目中常見的三種文件類型在線預(yù)覽實現(xiàn)(pdf/word/excel表格)
最近在項目中要做一個pdf在線預(yù)覽的功能,索性給大家整理個全面的,這篇文章主要給大家介紹了關(guān)于vue項目中常見的三種文件類型在線預(yù)覽實現(xiàn)的相關(guān)資料,文件類型分別是pdf/word文件/excel表格,需要的朋友可以參考下2022-05-05
vue cli 3.0下配置開發(fā)環(huán)境下的sourcemap問題
這篇文章主要介紹了vue cli 3.0下配置開發(fā)環(huán)境下的sourcemap問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-06-06

