判断是否为数字
export function isNumber(str) {
return /^[0-9.]*$/.test(str);
}
export function debounce(fn, wait = 250, immediate) {
let timeout
return function (...args) {
const later = () => {
timeout = null
if (!immediate) {
fn.apply(this, args)
}
};
clearTimeout(timeout)
if (immediate && !timeout) {
fn.apply(this, args)
}
timeout = setTimeout(later, wait)
}
}
export function throttle(fn, limit = 250) {
let wait = false
return function (...args) {
if (wait) {
return
}
wait = true
fn.apply(this, args)
setTimeout(() => {
wait = false
}, limit)
}
}
深拷贝数据
export function clone(data) {
return JSON.parse(JSON.stringify(data))
}
判断是否为对象
export function isObject(v) {
return Object(v) === v
}
判断是否为
export function isDate(v) {
return Object.prototype.toString.call(v) === '[object Date]'
}
export function isRegexp(v) {
return Object.prototype.toString.call(v) === '[object RegExp]'
}
判断是否为字符串
export function isString(v) {
return typeof v === 'string'
}
错误函数提示
export function errAction(response) {
this.$toast({type: 'danger', content: '网络或服务器异常,保存失败', time: 1500});
throw new Error(response)
}
网友评论