整理文档,搜刮出一个vue中用H5实现文件上传的方法实例代码,稍微整理精简一下做下分享。
fileSize) {
that.$dispatch('show-alert','msg_1016')
document.getElementById('fileToUpload').value = ''
} else {
var xhr = new XMLHttpRequest()
xhr.addEventListener('load',that.uploadComplete,false)
xhr.open('POST',that.$root.appBaseUrl + 'fileUpload/singleFileUpload')
xhr.send(fd)
}
}
}
},// 上传成功
'uploadComplete': function (evt) {
this.personInfo.photoUrl = (evt.target.responseText).replace('\\','/')
document.getElementById('fileToUpload').value = ''
},// 删除图片
'deleteImg': function () {
this.personInfo.photoUrl = ''
},