constNUMS='0123456789';constNUMSANDLETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';exportfunctionrandomStr(n, isPureNum =false){let possible = isPureNum ?NUMS:NUMSANDLETTERS;let ret ='';for(let i =0; i < n; i++){
ret += possible.charAt(Math.floor(Math.random()* possible.length));}return ret;}
6、获取路由中的path
exportfunctiongetUrlPath(){let href = location.href;let start = href.indexOf('/#')+2;let end = href.indexOf('?');if(end ===-1){
end = href.length;}return href.slice(start, end);}
// 获取类型exportfunctiongetType(obj){returnObject.prototype.toString.call(obj).slice(8,-1).toLowerCase();}// 判断类型exportfunctionisType(obj, type){if(this.getType(type)!=='string'){thrownewError('type param must be string in util.js');}returnthis.getType(obj)=== type;}// 是否是numberexportfunctionisNumber(val){returnthis.isType(val,'number');}exportfunctioncountDecimals(n){if(!this.isNumber(n)){
n =parseFloat(n);}if(Math.floor(n)=== n.valueOf()){return0;}return n.toString().split('.')[1].length;}