- vue 使用原生input + FormData上传文件
- 不用表单提交,form表单提交页面会跳转
<input type="file" ref="fileInput" />
<button @click="upload">上传</button>
upload() {
const files = this.$refs.fileInput.files
var formData = new FormData();
let config = {
headers: {
"Content-Type": "multipart/form-data",
},
};
formData.append("file", files[0]);
this.axios.post("/api/file/upload", formData, config).then((response) => {
this.$message.success(response.data);
});
},