废话不多说,上代码
原来的样子:
// return回去的是定义好的数组对象
function getColByType(type) {
console.log(type, 'type---------------55');
if (type == "jcxxList") {
return jcxx
} else if (type == 'tgxxList') {
return tgxx
} else if (type == 'sbzzList') {
return sbzzList
} else if (type == 'sbsjJyzbList') {
return sbsjJyzbList
} else if (type == 'jcxxFjkgList') {
return jcxxFjkgList
} else if (type == 'jcxxYlsfzzList') {
return jcxxYlsfzzList
} else if (type == 'jcxxLqqList') {
return jcxxLqqList
} else if (type == 'tgsDlList') {
return tgsDlList
} else if (type == 'jcxxByqyList') {
return jcxxByqyList
} else if (type == 'jcxxByqfznlList') {
return jcxxByqfznlList
} else if (type == 'jcxxZsspList') {
return jcxxZsspList
} else if (type == 'jcxxWxdgrspList') {
return jcxxWxdgrspList
} else if (type == 'jcxxWxdgrspList') {
return jcxxWxdgrspList
} else if (type == 'sbsjGgpList') {
return sbsjGgpList
} else if (type == 'sbsjZlpcnsList') {
return sbsjZlpcnsList
} else if (type == 'sbsjGlcList') {
return sbsjGlcList
} else if (type == 'sbsjDgcymList') {
return sbsjDgcymList
} else if (type == 'sbsjMfjList') {
return sbsjMfjList
} else if (type == 'sbsjCygList') {
return sbsjCygList
} else if (type == 'sbsjCygjnList') {
return sbsjCygjnList
} else if (type == 'sbsjYwjList') {
return sbsjYwjList
} else if (type == 'sbsjMwfxsqList') {
return sbsjMwfxsqList
} else if (type == 'sbsjQtjdqList') {
return sbsjQtjdqList
} else if (type == 'sbsjYzfjkgList') {
return sbsjYzfjkgList
} else if (type == 'sbsjWlcfjkgList') {
return sbsjWlcfjkgList
} else if (type == 'sbsjYlsfzzList') {
return sbsjYlsfzzList
} else if (type == 'sbsjYmwkqList') {
return sbsjYmwkqList
}
}
改造之后的样子:
function getColByType(type) {
console.log(type, 'type---------------55');
let list = {
"jcxxList": jcxx,
'tgxxList': tgxx,
'sbzzList': sbzzList,
'sbsjJyzbList': sbsjJyzbList,
'jcxxFjkgList': jcxxFjkgList,
'jcxxYlsfzzList': jcxxYlsfzzList,
'jcxxLqqList': jcxxLqqList,
'tgsDlList': tgsDlList,
'jcxxByqyList': jcxxByqyList,
'jcxxByqfznlList': jcxxByqfznlList,
'jcxxZsspList': jcxxZsspList,
'jcxxWxdgrspList': jcxxWxdgrspList,
'sbsjGgpList': sbsjGgpList,
'sbsjZlpcnsList': sbsjZlpcnsList,
'sbsjGlcList': sbsjGlcList,
'sbsjDgcymList': sbsjDgcymList,
'sbsjMfjList': sbsjMfjList,
'sbsjCygList': sbsjCygList,
'sbsjCygjnList': sbsjCygjnList,
'sbsjYwjList': sbsjYwjList,
'sbsjMwfxsqList': sbsjMwfxsqList,
'sbsjQtjdqList': sbsjQtjdqList,
'sbsjYzfjkgList': sbsjYzfjkgList,
'sbsjWlcfjkgList': sbsjWlcfjkgList,
'sbsjYlsfzzList': sbsjYlsfzzList,
'sbsjYmwkqList': sbsjYmwkqList,
}
return list[type] ? list[type] : false
}
是不是精简了很多,逻辑也更明确,甚至运行起来都感觉效率高了一点,不知道这是不是所谓的映射呢
推荐阅读
- web网页模板|如此优秀的JS轮播图,写完老师都沉默了
- 接口|axios接口报错-参数类型错误解决
- JavaScript|vue 基于axios封装request接口请求——request.js文件
- JavaScript|JavaScript — 初识数组、数组字面量和方法、forEach、数组的遍历
- JavaScript|JavaScript — call()和apply()、Date对象、Math、包装类、字符串的方法
- 前端|web前端dya07--ES6高级语法的转化&render&vue与webpack&export
- vue|Vue面试常用详细总结
- javascript|vue使用js-xlsx导出excel,可修改格子样式,例如背景颜色、字体大小、列宽等
- css|我用css精灵图拼接了自己的英文名字,不会还有人不知道精灵图技术吧()
- css|css三角的做法及其案例