最近有个需求,在页面上有个按钮可以选取文件然后在导出到其它地方,

说明白点就是文件的读取与写入,下面是例子(例子中用到了fileSave.js github地址:https://github.com/eligrey/FileSaver.js)

首先引入fileSave.js   

import '~/lib/file-saver/dist/FileSaver.min.js';

html:

<input type="file" >转移</button>

 

script:

$scope.fileChoose = (ele) => {
$scope.files = ele.files[0];//读取文件信息
};
$scope.chaunshu = () => {
if($scope.files == '' || $scope.files == undefined ){
layer.alert('请先选择文件', {closeBtn: false, icon: 2}, index => {
layer.close(index);
});

}else {
let filename = $scope.files.name;
let type = $scope.files.type;
let blob = new Blob([$scope.files], {type: type}); //[$scope.files]要保存的文件 {type:保存文件类型}
saveAs(blob, filename);//保存
}

相关文章:

  • 2022-12-23
  • 2022-02-14
  • 2021-11-24
  • 2022-12-23
  • 2022-12-23
  • 2021-04-02
  • 2021-07-15
猜你喜欢
  • 2022-12-23
  • 2021-12-13
  • 2022-12-23
  • 2022-12-23
  • 2021-08-10
  • 2021-08-18
  • 2022-12-23
相关资源
相似解决方案