图片上传

图片上传

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('修改成功');
  }
}
posted @ 2020-08-28 23:07  彼_岸  阅读(107)  评论(0编辑  收藏  举报