vue 上传图片
vue使用FormData()、axios上传图片
//main.js import Vue from 'vue' import axios from 'axios' const instance = axios.create({ baseUrl:'http://localhost:8080/rph', timeout:5000, headers:{'Content-Type':'multipart/form-data'} }) Vue.prototype.$instance = instance;
wenj文件上传代码
uploadImgFile(){ let formData = new FormData(); formData.append("id",this.id); formData.append("imgUrl",this.img); this.$instance.post('/addReceiptImg',formData) .then((res)=>{ console.log(res); }) .catch((err)=>{ console.log(err); }) }