大家好,又见面了,我是你们的朋友全栈君
html代码段:
<input type="file" @change.prevent.stop="upload">
vue 中script代码段:
data() {
fileName: ''
},
methods: {
upload(event) {
let files = event.target.files[0];
this.fileName = this.getObjectUrl(files);
},
getObjectUrl(file) {
let url = null;
if (window.createObjectURL != undefined) {
// basic
url = window.createObjectURL(file);
} else if (window.webkitURL != undefined) {
// webkit or chrome
url = window.webkitURL.createObjectURL(file);
} else if (window.URL != undefined) {
// mozilla(firefox)
url = window.URL.createObjectURL(file);
}
return url;
}
}
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/160948.html原文链接:https://javaforall.cn