Vue中util的工具函数,下面通过实例代码给大家介绍的非常详细,具体代码如下所示:
// 防抖函数 function debounce (fn, wait) { let t return () => { let cOntext= this let args = arguments if (t) clearTimeout(t) t = setTimeout(() => { fn.apply(context, args) }, wait) } } function flatten (arr) { // 数组扁平化 return arr.reduce((result, item) => { return result.concat(Array.isArray(item) ? flatten(item) : item) }, []) } function handleMulitePerson (sPerson) { console.log(44, sPerson.split(',')) if (typeof sPerson == 'string') { let persOnArr= [] sPerson.split(',').forEach(item => { let obj = { userCode: item.split('/')[0], userName: item.split('/')[1] } personArr.push(obj) }) return personArr } } function uniqueArray (array, key) { // json数组根据key去重 var result = [array[0]] for (var i = 1; i0 ? location.search.substring(1) : '' var items = str.length ? str.split('&') : [] var args = {} var item = null var name = null var value = null for (let i = 0, len = items.length; i 0 ? window.location.hash.substring(window.location.hash.indexOf('?') + 1) : '' var items = str.indexOf('&') > 0 ? str.split('&') : str.split('?') var args = {} var item = null var name = null var value = null for (let i = 0, len = items.length; i 0) { var queryStr = url.substring(idx + 1) if (queryStr.length > 0) { var arr = queryStr.split('&') for (let i = 0; i 0) { params[pair[0]] = pair[1] } } } } return params } /** 选人下拉框数据:username(userCode) */ function getSelectUserName (userName, userCode) { return userName + '(' + userCode + ')' } function getSelectLoginUser () { var userInfo = getLoginUserInfo() return getSelectUserName(userInfo.userName, userInfo.userId) } function getUserNameBySelectUserName (userName) { let i = userName.indexOf('(') return userName.substring(0, i) } /** 登录用户信息 userId userName mobileNo @returns {any} */ function getLoginUserInfo () { return JSON.parse(localStorage.getItem('userInfo')) } function getLoginUserCode () { return JSON.parse(localStorage.getItem('userInfo')).userId } export default { getNyr, getYDate, setSessionStorage, urlParams, urlAfterParams, parseParams, debounce, handleMulitePerson, uniqueArray, flatten, getSessionStorage, removeStorage, getSelectUserName, getSelectLoginUser, getLoginUserInfo, getLoginUserCode, getUserNameBySelectUserName }
总结
以上所述是小编给大家介绍的Vue中util的工具函数实例详解,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!