vue . ? ?input upload 上傳圖片時(shí)無(wú)法傳輸?shù)胶笈_(tái)权悟,所以需要轉(zhuǎn)換砸王;如下格式 ? ? ?
param.append('image',file,file.name) 需要三個(gè)參數(shù),鍵值對(duì)峦阁,文件谦铃,文件名;文件就是 ? @change觸發(fā) ?獲取 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();//創(chuàng)建form對(duì)象
param.append('image',file,file.name);//通過(guò)append向form對(duì)象添加數(shù)據(jù)
// param.append('chunk','0');//添加form表單中其他數(shù)據(jù)
console.log(param.get('image'));//FormData私有類對(duì)象榔昔,訪問(wèn)不到驹闰,可以通過(guò)get判斷值是否傳進(jìn)去
值傳遞給后臺(tái)注意,傳入的是是對(duì)象還是數(shù)組?
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;'}
}
//添加請(qǐng)求頭
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{}