根据代码修改给我完整的
时间: 2024-03-21 22:39:37 浏览: 11
根据您提供的代码,我做了一些修改,将其改为循环删除imgList数组中的元素。具体代码如下:
```
let filePaths = that.imgList;
console.log(filePaths);
filePaths.forEach((filePath) => {
// 首先判断文件是否存在
uni.getFileInfo({
filePath: filePath,
success: () => {
console.log('文件存在');
uni.removeSavedFile({
filePath: filePath,
success: () => {
console.log('成功删除本地缓存中的文件');
// 从 imgList 数组中删除对应的元素
let index = that.imgList.indexOf(filePath);
if (index !== -1) {
that.imgList.splice(index, 1);
}
that.saveData = [];
const taskData = JSON.stringify(this.fromData);
uni.removeStorageSync(this.fromData.number, taskData);
},
fail: (err) => {
console.log('删除本地缓存中的文件失败', err);
},
});
},
fail: (err) => {
console.log('文件不存在', err);
// 如果文件不存在,则直接从 imgList 数组中删除对应的元素
let index = that.imgList.indexOf(filePath);
if (index !== -1) {
that.imgList.splice(index, 1);
}
that.saveData = [];
},
});
});
```
这里使用forEach()方法遍历imgList数组中的元素,然后判断文件是否存在,如果存在则删除对应的本地缓存文件以及从imgList数组中删除对应的元素;如果不存在,则直接从imgList数组中删除对应的元素。最后更新saveData数组并从本地缓存中删除对应的数据。