Vue.prototype.checkMoney = function (val){
val = val.replace(/[^\d.-]/g,"");
val = val.replace(/^\./g,"");
val = val.replace(/\.{2,}/g,".");
val = val.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
val = val.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');
return val
}
Vue.prototype.formatMoney = function(val){
if(!val) {
return "0.00"
}
let str = parseFloat(val).toFixed(2) + '';
let intSum = str.substring(0,str.indexOf(".")).replace( /\B(?=(?:\d{3})+$)/g, ',' );
let dot = str.substring(str.length,str.indexOf("."))
return intSum + dot;
}
function isPromise (val) {
return (
isDef(val) &&
typeof val.then === 'function' &&
typeof val.catch === 'function'
)
}
function isObject (obj) {
return obj !== null && typeof obj === 'object'
}
function isUndef (v) {
return v === undefined || v === null
}
function isDef (v) {
return v !== undefined && v !== null
}
// 是否以$ || _ 开头
function isReserved (str) {
var c = (str + '').charCodeAt(0)
return c === 0x24 || c === 0x5F
}
function filterEditorDataTab(str) {
return str.replace(/<[^>]+>/g, "")
}
input_value: function (newVal, oldVal) {
if (this.check_money && newVal != oldVal) {
this.input_value = (newVal + "")
.replace(/[^\d.-]/g, "")
.replace(/^\./g, "")
.replace(/\.{2,}/g, ".")
.replace(/\-{2,}/g, "-")
.replace(".", "$#$")
.replace(/\./g, "")
.replace("$#$", ".")
.replace(/^(\-)*(\d+)\.(\d\d).*$/, "$1$2.$3");
}
},
vue 里的
// 1、蛇形命名 转 驼峰
function cached (fn){
const cache = Object.create(null)
return function cachedFn(str) {
const hit = cache[str]
return hit || (cache[str] = fn(str))
}
}
/**
* Camelize a hyphen-delimited string.
*/
const camelizeRE = /-(\w)/g
const camelize = cached((str) => {
return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''))
})
// const name = camelize('aaa')
// const name1 = camelize('-aaa')
// const name2 = camelize('bbb')
// const name3 = camelize('c-cc')
// const name4 = camelize('aa-a')
// console.log('------name', name)
// console.log('------name1', name1)
// console.log('------name2', name2)
// console.log('------name3', name3)
// console.log('------name4', name4)