Vue 文件上传组件代码示例
<template>
<div>
<input type='file' ref='fileInput' @change='handleFileChange'>
<button @click='uploadFile'>上传文件</button>
</div>
</template>
<script>
export default {
data() {
return {
file: null
};
},
methods: {
handleFileChange(event) {
this.file = event.target.files[0];
},
uploadFile() {
const formData = new FormData();
formData.append('file', this.file);
axios.post('/api/upload', formData).then(response => {
console.log(response.data);
});
}
}
};
</script>
原文地址: https://www.cveoy.top/t/topic/noE5 著作权归作者所有。请勿转载和采集!