ionic 文件修改后保存自动移除该文件

1.开发环境

win10 64

VS2015

ionic1

.NET Framework 4.5



具体操作步骤如下

文件保存后 当前html自动移除项目 有没有大神遇到过?

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
Ionic中,你可以使用`File`插件来处理文件操作。要复制文件并将其保存到新目录,可以按照以下步骤进行操作: 1. 导入`File`插件 在你的Ionic项目中,运行以下命令来安装`File`插件: ``` ionic cordova plugin add cordova-plugin-file npm install @ionic-native/file ``` 在需要使用`File`插件的组件中导入它: ``` import { File } from '@ionic-native/file/ngx'; ``` 2. 复制文件到新目录 使用`File`插件的`copyFile()`方法来复制文件。该方法需要四个参数: - 原始文件路径 - 原始文件名 - 目标目录路径 - 目标文件名 以下是一个示例代码,可以将`/src/assets/file.txt`文件复制到`/src/assets/copy`目录中的`copy.txt`文件中: ``` import { File } from '@ionic-native/file/ngx'; constructor(private file: File) {} // 复制文件到新目录 copyFile() { const sourceFilePath = this.file.applicationDirectory + 'www/assets/file.txt'; const sourceFileName = 'file.txt'; const targetDirPath = this.file.applicationDirectory + 'www/assets/copy'; const targetFileName = 'copy.txt'; this.file.checkDir(this.file.applicationDirectory, 'www/assets/copy') .then(() => { console.log('目录已存在'); this.file.copyFile(sourceFilePath, sourceFileName, targetDirPath, targetFileName) .then(() => console.log('文件已复制')) .catch(err => console.log('文件复制失败:', err)); }) .catch(() => { console.log('目录不存在'); this.file.createDir(this.file.applicationDirectory + 'www/assets', 'copy', false) .then(() => { console.log('目录已创建'); this.file.copyFile(sourceFilePath, sourceFileName, targetDirPath, targetFileName) .then(() => console.log('文件已复制')) .catch(err => console.log('文件复制失败:', err)); }) .catch(err => console.log('目录创建失败:', err)); }); } ``` 在上面的示例代码中,我们首先检查目标目录是否已存在,如果目录存在,则直接复制文件。如果目录不存在,则先创建目录,然后再复制文件。 注意,在使用`File`插件时,需要在`config.xml`文件中添加以下配置: ``` <platform name="android"> <allow-intent href="market:*" /> <allow-intent href="geo:*" /> <allow-intent href="mailto:*" /> <allow-intent href="sms:*" /> <allow-intent href="tel:*" /> <allow-intent href="http:*" /> <allow-intent href="https:*" /> <allow-intent href="cdvfile:*" /> </platform> ``` 这样就可以实现在Ionic中复制文件保存到新目录了。
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值