可以使用对象字典来优化代码,减少重复的代码。

const timerFormat = {
  day: 'YYYY-MM-DD',
  month: 'YYYY-MM',
  year: 'YYYY'
}

this.timerValue = this.$moment(val).format(timerFormat[this.timerType])
以下代码如何优化if thistimerType == day 					thistimerValue = this$momentvalformatYYYY-MM-DD				 else if thistimerType == month 					thistimerValue = this$momentvalformatYYYY-MM				 else if thistimerType == y

原文地址: https://www.cveoy.top/t/topic/h24V 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录