图片上传
图片上传
Created: Aug 26, 2020 4:32 PM
分类: 技术点
技术: 图片上传
文件: src/views/Edit.vue
/**
* 图片上传
* @param file 图片
* @returns {Promise<void>}
*/
async afterRead(file) {
// 此时可以自行将文件上传至服务器
const fromdata = new FormData()
fromdata.append('file', file.file)
// 上传到文件服务器
const res = await this.$http.post('/upload', fromdata)
// 重新获取图片
this.model.user_img = res.data.url
this.userUpdate()
},
/**
* 上传全部数据,让后台数据修改
* @returns {Promise<void>}
*/
async userUpdate() {
const res = await this.$http.post('/update/' + localStorage.getItem('id'), this.model)
if (res.status === 200) {
Toast.success('修改成功');
}
}