
组件库review总结
封装好的组件库源码分析
luckybing~
一个积极向上、乐观开朗、遇到Bug想一晚上、没秃顶、会写段子的web前端工程师
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
(六) 地址栏相关字段解析
1. 在地址栏添加参数/修改参数 返回新的拼接结果 function addUrlParams(args, search = window.location.search || '') { if (Object.prototype.toString.call(args) !== '[object Object]') { throw new Error('addUrlParams(): 参数类型不正确') return } var obj =原创 2020-05-12 11:10:19 · 430 阅读 · 0 评论 -
(五) url 参数转换
1. 把 ?a=1&b=2 转换成 {a:1,b:2} window.location.search 可以 获取到 类似 ?a=1&b=2 这种 url 参数 function parse (search) { if (typeof search !== 'string') { throw new Error('parse(): 传入参数类型不正确') } if (search.indexOf('?') > -1) { ...原创 2020-05-11 16:13:56 · 674 阅读 · 0 评论 -
(四) class类名相关封装
1. 添加类名 两个参数 第一个为操作的对象 剩余参数为类名 function addClass (obj, ...className) { className.forEach((item) => { if (typeof item === 'string') { obj.classList.add(item) } else { throw new Error('类名参数应为字符串') }原创 2020-05-09 15:45:10 · 218 阅读 · 0 评论 -
(三) 获取定位promise封装
// options 非必传 function getLocation (options = {}) { const resultPromise = new Promise((resolve, reject) => { if (navigator.geolocation && navigator.geolocation.getCurrentPosition) { navigator.geolocation.getCurrentP.原创 2020-05-09 11:00:22 · 354 阅读 · 0 评论 -
(一)数组review
1. 数组去重 function uniq(arr) { if (arr instanceof Array) { return Array.from(new Set(arr)) } else { throw new Error('参数格式不正确') } } 2. 数组取交集 自己写的 function intersection (firArr, secArr) { if (firArr instanceof Array && arr2 i原创 2020-05-09 10:28:45 · 170 阅读 · 0 评论