const passwordChangeable = userInfo.password_changeable === 'y' || userInfo.password_changeable === 'Y' ? this.$t('yes') : userInfo.password_changeable === 'n' || userInfo.password_changeable === 'N' ? this.$t('no') : userInfo.password_changeable 优化这段代码
时间: 2024-03-27 08:40:02 浏览: 49
这段代码可以使用一个更简洁的三元运算符来进行优化,如下所示:
```
const passwordChangeable = (userInfo.password_changeable === 'y' || userInfo.password_changeable === 'Y') ? this.$t('yes') : (userInfo.password_changeable === 'n' || userInfo.password_changeable === 'N') ? this.$t('no') : userInfo.password_changeable;
```
也可以使用一个更易读的 if/else 语句来进行优化,如下所示:
```
let passwordChangeable;
if (userInfo.password_changeable === 'y' || userInfo.password_changeable === 'Y') {
passwordChangeable = this.$t('yes');
} else if (userInfo.password_changeable === 'n' || userInfo.password_changeable === 'N') {
passwordChangeable = this.$t('no');
} else {
passwordChangeable = userInfo.password_changeable;
}
```
阅读全文