vue 上传文件
作者:
麓语 | 来源:发表于
2018-07-09 11:12 被阅读0次
<input type="file" id="fileExport" @change="handleFileChange" ref="inputer">
methods:{
handleFileChange (e) {
let inputDOM = this.$refs.inputer;
// 通过DOM取文件数据
this.file = inputDOM.files[0];
this.errText = '';
let size = Math.floor(this.file.size / 1024);
console.log(this.file)
//new一个FileReader实例
let reader = new FileReader();
let _this = this;
// reader.readAsText(this.file) //文本读取,默认utf-8,格式 其他格式:reader.readAsText(this.file, "GBK")
reader.readAsDataURL(this.file) //base 64 读取
reader.onload=function(e){
// 读取结果
console.log(this.result)
// if (size > ...) {
// // 这里可以加个文件大小控制
// return false
// }
}
},
}
本文标题:vue 上传文件
本文链接:https://www.haomeiwen.com/subject/xnuzuftx.html
网友评论