html:
<input id="file" type="file" @change="tirggerFile($event)">
js:
export default{
data(){
return{
userInfo: '',
headimgurl: {}
}
},
methods: {
tirggerFile (e) {
this.headimgurl = new FormData(); // 創建一個form類型的數據
this.headimgurl.append("headimgurl",e.target.files[0]); // 獲取上傳文件的數據
// 往對象插入數據
this.headimgurl.append("name",this.userInfo.name);
this.headimgurl.append("paperwork_type",this.userInfo.paperwork_type);
this.headimgurl.append("paperwork_num",this.userInfo.paperwork_num);
this.headimgurl.append("phone",this.userInfo.phone);
this.headimgurl.append("sex",sex);
this.headimgurl.append("city",this.userInfo.city);
this.headimgurl.append("area",this.userInfo.area);
this.headimgurl.append("school",this.userInfo.school);
this.headimgurl.append("grade",grade);
axios.post("User/updateUserInfo",this.headimgurl).then((res)=>{
if (res.data.status === 1) {
// 清空file的值
var file = document.getElementById('file');
file.outerHTML = file.outerHTML;
// 重新獲取數據
this.information()
alert(res.data.message)
} else {
alert(res.data.message)
}
})
}
}
}
vue傳file文件對象
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.