封装的上传方法

151 阅读1分钟
private exportExcel(url ?: any, body ?: any, text ?: string) {
  const token = window.$globalHub.$store.state.user.userInfo.token;
  // @ts-ignore
  this.$axios.request({
    method: 'get',
    url,
    data: body,
    responseType: 'blob',
    headers: {
      Authorization: `Bearer ${token}`
    }
  }).then((res: any) => {
    const result = res.data;
    const herfs = window.URL.createObjectURL(new Blob([result]));
    const link = document.createElement('a');
    link.style.display = 'none';
    link.href = herfs;
    link.setAttribute('download', `${text}.xlsx`);
    document.body.appendChild(link);
    link.click();
  }).catch((err: any) => {
    this.$message.error(err.message);
  });
}