vue传file文件对象
html:<input id="file" type="file" @change="tirggerFile($event)">js:export default{data(){return{userInfo: '',headimgurl: {}}},methods: {tirggerFile (e) {this.headimgurl = new FormData(); // 创建一个
·
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)
}
})
}
}
}
更多推荐
已为社区贡献8条内容
所有评论(0)