Vue中util的工具函数实例详解
Vue中util的工具函数,下面通过实例代码给大家介绍的非常详细,具体代码如下所示:
//防抖函数
functiondebounce(fn,wait){
lett
return()=>{
letcontext=this
letargs=arguments
if(t)clearTimeout(t)
t=setTimeout(()=>{
fn.apply(context,args)
},wait)
}
}
functionflatten(arr){//数组扁平化
returnarr.reduce((result,item)=>{
returnresult.concat(Array.isArray(item)?flatten(item):item)
},[])
}
functionhandleMulitePerson(sPerson){
console.log(44,sPerson.split(','))
if(typeofsPerson=='string'){
letpersonArr=[]
sPerson.split(',').forEach(item=>{
letobj={userCode:item.split('/')[0],userName:item.split('/')[1]}
personArr.push(obj)
})
returnpersonArr
}
}
functionuniqueArray(array,key){//json数组根据key去重
varresult=[array[0]]
for(vari=1;i0?location.search.substring(1):''
varitems=str.length?str.split('&'):[]
varargs={}
varitem=null
varname=null
varvalue=null
for(leti=0,len=items.length;i0?window.location.hash.substring(window.location.hash.indexOf('?')+1):''
varitems=str.indexOf('&')>0?str.split('&'):str.split('?')
varargs={}
varitem=null
varname=null
varvalue=null
for(leti=0,len=items.length;i0){
varqueryStr=url.substring(idx+1)
if(queryStr.length>0){
vararr=queryStr.split('&')
for(leti=0;i0){
params[pair[0]]=pair[1]
}
}
}
}
returnparams
}
/**
选人下拉框数据:username(userCode)
*/
functiongetSelectUserName(userName,userCode){
returnuserName+'('+userCode+')'
}
functiongetSelectLoginUser(){
varuserInfo=getLoginUserInfo()
returngetSelectUserName(userInfo.userName,userInfo.userId)
}
functiongetUserNameBySelectUserName(userName){
leti=userName.indexOf('(')
returnuserName.substring(0,i)
}
/**
登录用户信息
userId
userName
mobileNo
@returns{any}
*/
functiongetLoginUserInfo(){
returnJSON.parse(localStorage.getItem('userInfo'))
}
functiongetLoginUserCode(){
returnJSON.parse(localStorage.getItem('userInfo')).userId
}
exportdefault{
getNyr,
getYDate,
setSessionStorage,
urlParams,
urlAfterParams,
parseParams,
debounce,
handleMulitePerson,
uniqueArray,
flatten,
getSessionStorage,
removeStorage,
getSelectUserName,
getSelectLoginUser,
getLoginUserInfo,
getLoginUserCode,
getUserNameBySelectUserName
}
总结
以上所述是小编给大家介绍的Vue中util的工具函数实例详解,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。