优化这段代码if (this.mode === 'create') { this.uuid = uuid.generate() this.uploadId = this.uuid } else { this.uuid = this.id this.uploadId = this.uuid value.time = value.time ? moment(value.time) : null if (!this.resubmitMode) { this.$nextTick(() => { this.$refs.upFile.loadFiles() }) } else { this.uploadId = uuid.generate() } }
时间: 2024-02-14 18:08:51 浏览: 69
这段代码可以进行如下优化:
```
if (this.mode === 'create') {
this.uuid = this.uploadId = uuid.generate();
} else {
this.uuid = this.uploadId = this.id;
value.time = value.time ? moment(value.time) : null;
if (!this.resubmitMode) {
this.$nextTick(() => {
this.$refs.upFile.loadFiles();
});
} else {
this.uploadId = uuid.generate();
}
}
```
可以看到,我将 `this.uuid` 和 `this.uploadId` 的赋值放到了一起,并且使用了统一的赋值方式。同时,我也将 `if` 和 `else` 的代码块内部的代码进行了整理,尽量使得代码更加简洁易懂。
阅读全文