【发布时间】:2022-11-23 04:11:30
【问题描述】:
我有可以正常运行的代码,我怎样才能更好地编写这段代码
if (!this.isThis) {
return [
{ label: this.$t('profile'), value: this.acc.AccountNumber, id: 'ProfileNumber' },
]
} else {
return [
{ label: this.$t('market'), value: this.acc.label, id: 'market' },
{ label: this.$t('profile'), value: this.acc.AccountNumber, id: 'ProfileNumber' },
{ label: this.$t('account'), value: this.acc.profile, id: 'account' }
]
}
我可以使用一些更好的 js 代码来处理这个问题,上面的工作但是有更好的方法来编写
【问题讨论】:
-
imo,这很简单。也许删除
else,因为它无论如何都会在return上退出。这就是eslint规则会做的:eslint.org/docs/latest/rules/no-else-return -
我赞赏您优化代码的愿望,使它更苗条且更易于维护。请记住,优化太多了。 (但事实并非如此。)
标签: javascript vue.js