摘要: 编码优化: 不要将所有的数据都放在data中,data中的数据都会增加getter和setter,会收集对应的 watcher vue 在 v-for 时给每项元素绑定事件需要用事件代理 SPA 页面采用keep-alive缓存组件 拆分组件( 提高复用性、增加代码的可维护性,减少不必要的渲染 ) 阅读全文
posted @ 2021-02-26 13:37 hwjun 阅读(181) 评论(0) 推荐(0) 编辑
摘要: const data = { a: '小aa', b: '小bb', c: { cc: '小cc' } } const tmpl = '哈哈,我是${a},你叫${b},他是${c.cc}' function render (tmpl, data) { const getData = (key) = 阅读全文
posted @ 2021-02-24 17:52 hwjun 阅读(65) 评论(0) 推荐(0) 编辑
摘要: function add() { let args = Array.prototype.slice.call(arguments) let add1 = function() { args = args.concat([...arguments]) return add1 } add1.toStri 阅读全文
posted @ 2021-02-24 16:09 hwjun 阅读(46) 评论(0) 推荐(0) 编辑
摘要: /** * @param {string} url * @returns {Object} */ function param2Obj (url) { const search = url.split('?')[1] if (!search) { return {} } return JSON.pa 阅读全文
posted @ 2021-02-23 14:30 hwjun 阅读(66) 评论(0) 推荐(0) 编辑
摘要: var quickSort = function(arr) { if(arr.length<=1) return arr; var left = [], right = [], point = Math.floor(arr.length/2); var middle = arr.splice(poi 阅读全文
posted @ 2021-02-23 13:39 hwjun 阅读(32) 评论(0) 推荐(0) 编辑
摘要: function debounce(fn, wait, immediate) { let timer; return function() { const context = this; const args = arguments; timer && clearTimeout(timer); if 阅读全文
posted @ 2021-02-23 11:49 hwjun 阅读(41) 评论(0) 推荐(0) 编辑
摘要: Function.prototype.call = function(ctx) { var ctx = ctx || window; ctx.fn = this; var args = []; for(var i = 1, len = arguments.length; i < len; i++) 阅读全文
posted @ 2021-02-23 11:47 hwjun 阅读(46) 评论(0) 推荐(0) 编辑
摘要: /** * 深克隆 */ function deepClone(obj) { if(obj null) return null; if(typeof obj !== 'object') return obj; var newObj = obj instanceof Array ? [] : {}; 阅读全文
posted @ 2021-02-23 11:44 hwjun 阅读(60) 评论(0) 推荐(0) 编辑
摘要: function unique(arr) { var ret = []; var tmp = {}; for(var i = 0, len = arr.length; i < len; i++){ if(!tmp[typeof arr[i] + arr[i]]) { // 区分1 & '1' tmp 阅读全文
posted @ 2021-02-23 11:43 hwjun 阅读(19) 评论(0) 推荐(0) 编辑
摘要: class EventEmmiter { constructor() { this._events = {} } on(type, cb) { if(Array.isArray(type)) { type.forEach(tp => this.on(tp, cb)) } else { (this._ 阅读全文
posted @ 2021-02-23 11:35 hwjun 阅读(141) 评论(0) 推荐(0) 编辑