当前位置: 首页 > Web前端 > vue.js

vue中常用的util.js工具函数

时间:2023-03-31 16:02:57 vue.js

获取屏幕缩放比例getDeviceRatio(){varisAndroid=window.navigator.appVersion.match(/android/gi);varisIPhone=window.navigator.appVersion.match(/iphone/gi);vardevicePixelRatio=window.devicePixelRatio;变量dpr;if(isIPhone){//iOS下,2屏和3屏,使用2倍方案,其余使用1倍方案if(devicePixelRatio>=3){dpr=3;}elseif(devicePixelRatio>=2){dpr=2;}否则{dpr=1;}}else{//在其他设备下,仍然使用1-fold方案dpr=1;}returndpr}获取URL参数并返回一个对象getRequest(){consturl=location.search;//获取“?”后面的字符串url中的字符lettheRequest=newObject();如果(url.indexOf("?")!=-1){让str=url.substr(1);让strs=str.split("&");for(leti=0;i0){varoffset=document.cookie.indexOf(search);if(offset!=-1){offset+=search.length;varend=document.cookie.indexOf(";",offset);if(end==-1)end=document.cookie.length;返回unescape(document.cookie.substring(offset,end));}否则返回“”;}},删除所有cookiesclearCookie(){vardate=newDate();date.setTime(date.getTime()-10000);varkeys=document.cookie.match(/[^=;]+(?==)/g);console.log("需要删除的cookie名称:"+keys);如果(键){对于(vari=keys.length;i--;)document.cookie=keys[i]+"=0;expire="+date.toGMTString()+";path=/";}},