优化 Vue 代码:简化逻辑和类型转换
onLoad(option) { this.$nextTick(() => { const { roleCn } = uni.getStorageSync('userInfo'); this.role = roleCn; let activeTabKey = this.role === '总经理' ? 0 : (option.activeTabKey || this.rolesPower[this.role].dailyTabsList[0].key); this.current = this.rolesPower[this.role].dailyTabsList.findIndex(item => item.key === parseInt(activeTabKey)); this.activeTab = parseInt(activeTabKey); }); },
// Changes Made: // 1. Removed unnecessary duplication of code // 2. Simplified the ternary operator // 3. Used parseInt() instead of subtracting 0 to convert string to number.
原文地址: https://www.cveoy.top/t/topic/mKhu 著作权归作者所有。请勿转载和采集!