swan.removeSavedFile
解释:删除本地存储的文件
方法参数
Object object
object参数说明 :
示例
在开发者工具中预览效果
扫码体验
请使用百度APP扫码
图片示例
代码示例
-
Page({ data: { filePath: '' }, saveFile() { this.toast('正在保存', 'loading'); swan.downloadFile({ url: 'https://smartprogram.baidu.com/docs/img/file-simple.pdf', success: res => { swan.saveFile({ tempFilePath: res.tempFilePath, success: res => { this.toast('保存成功', 'none'); this.setData({ 'filePath': res.savedFilePath, 'disabled': false }); }, fail: err => { this.toast('保存失败,请稍后重试', 'none'); } }); }, fail: err => { this.toast('保存失败,请稍后重试', 'none'); } }); }, getSavedFileList() { swan.getSavedFileList({ success: res => { swan.showModal({ title: 'success', content: '目前保存文件数' + res.fileList.length }); console.log('getSavedFileList success', res.fileList); this.setData({ filelist: res.fileList}) }, fail: err => { this.toast('getSavedFileList', 'none'); console.log('getSavedFileList fail', err); } }); }, deleteFile() { const filePath = this.getData('filelist'); if (filePath.length > 0) { swan.removeSavedFile({ filePath: filePath[0].filePath, success: res => { this.toast('已删除', 'none'); }, fail: err => { this.toast('操作失败,请稍后重试', 'none'); } }) } }, toast(title, icon) { swan.showToast({title, icon}); }});
