vue . input upload 上传图片时无法传输到后台,所以需要转换;如下格式
param.append('image',file,file.name) 需要三个参数,键值对,文件,文件名;文件就是 @change触发 获取 e.target.files[0]; 然后传输
Select an image
删除img
importaxiosfrom'axios';
varqs=require('qs');
exportdefault{
props:['message'],
data() {
return{
quote:'',
datas:100,
a:'',
form:'',
image:''
}
},
methods:{
onFileChange1($event){
letfile=e.target.files[0];
letparam=newFormData();//创建form对象
param.append('image',file,file.name);//通过append向form对象添加数据
// param.append('chunk','0');//添加form表单中其他数据
console.log(param.get('image'));//FormData私有类对象,访问不到,可以通过get判断值是否传进去
值传递给后台注意,传入的是是对象还是数组
letconfig={
headers:{
'Content-Type':'multipart/form-data',
'Authorization':'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjBmMTgwM2I5MTM2YTY0NzAyZGU1MzMyZWY2MGI2NWQ2ZDJlZDJhZWMwMTE0MTdjMmM2MjllMWUzOGNiOTlmNzY5MTBlOGI5ZTYwZmM0NDAxIn0.eyJhdWQiOiIyIiwianRpIjoiMGYxODAzYjkxMzZhNjQ3MDJkZTUzMzJlZjYwYjY1ZDZkMmVkMmFlYzAxMTQxN2MyYzYyOWUxZTM4Y2I5OWY3NjkxMGU4YjllNjBmYzQ0MDEiLCJpYXQiOjE1MDYzODg5MDMsIm5iZiI6MTUwNjM4ODkwMywiZXhwIjoxNTA2OTkzNjk4LCJzdWIiOiI5MyIsInNjb3BlcyI6W119.h6QuP1aST7Sk0YnJ06jaKlJNaAg-M0J285X-AjiyZjuMN2dPlv1ol0zE3XygcC6PNBVBKXQwzQbvYJjhRfv87ctWlcqk2dCyonic9dz8yuU3aUcj5u9rWC7pal5t8rJRAtR805lAV_ydj3fo61Qg4iQ-Oq3_yb1LrADeT-52Q11X0NhWxEX83D5cw7c2_0tFFlsi0BqR5lU0tdyA-ZBpoSGhuOCJOvsGeDA0_gWkr9T5cVjnZoiKqsOyD4ubmcv6Y6dUXjdoyaMdZ7d4WxzVEkDO7f3vTzBK1JT27SOHyLjq0i8pehgojDUeoNVPVEgtjH7R3qI-BzdycdNLw_zX0AaFdmshmGAOuKZEwxVxTnBvoFl4OFxVU89ZB_9OGxLETJvNpayqsU3uqKK9osO3oSEC7Q-jf6KooAadt3uu5pLEcaeIJoj-x9ifyM1EJG3JUe_-sHJxgEqKaipiI6OgoyFhCQ7eTGQJp7hd7me51sZMozi4-Qic2DZE8cnV1wgZYwPAPXDlxM2vElkbkLP75tn2iL33ahzRg7qV7fvdTfXhod_oz2Uaqi91_ERM6sVQFOcTRF_wNn_FftOG_Trbo2GEmlQJcj38MOUvYhKLw7eSXL88P3HdZZEB2LYoiwnVo7ILCIyxaxW6Dp35tExgKOzY9wZIRxWrLSUENJNTLCk;'}
}
//添加请求头
axios.post('http://sapi.seekleather.cn/api/match/img_uploade',param,config)
.then(response=>{
console.log(response.data,"pppp");
})
},
},
beforeMount:function() {
let_this=this;
// this.daojishi1()
// axios.get('http://sapi.seekleather.cn/api/match/offer/match_offer').then(function(res) {
// _this.quote = res.data.data;
// // console.log(res)
// }, function(error) {
// console.log(error)
// });
},
}
#app{
text-align:center;
}
img{
width:30%;
margin:auto;
display:block;
margin-bottom:10px;
}
button{}