name:
1.showOrHidden(显示隐藏) ==> toggle(切换)
performance:
1.
//bad
if (key.indexOf('Date') != -1){}
//good
if(key.includes('Date')){}
//bad
if(data[key] !=="" || data[key] !== null || data[key] !== undefined){}
//goodif (isEmpty(data[key])) {}
// 判断是否为空
// 空数组 / null / undefined / 空字符串
export function isEmpty(val) {if (Array.isArray(val) && val.length === 0) {return true} else if (val == null) {return true} else if (typeof val === 'string' && val === '') {return true} else {return false}
}
code:
1.
//抽离变量做配置项
//bad
<div v-if="item.labelAndKeyArr.length > 6">TODO</div>
//good
showConst=6
<div v-if="item.labelAndKeyArr.length > showConst">TODO</div>
2.不建议使用for in 遍历数组,因为输出的顺序是不固定的 建议用for of 代替