为了账号安全,请及时绑定邮箱和手机立即绑定

如何使这个函数更小?

如何使这个函数更小?

PIPIONE 2021-06-29 04:39:15
我想通过删除发送到 htttp.post 的变量并将它们放入数组来优化以下函数。这可能吗?将变量放在普通数组中,但出现布尔错误。  getUsers(val) {    this.spinner.show();    const options = {      headers: new HttpHeaders().set('x-access-token', this.currentUser.token),      responseType: 'blob' as 'json'    };    return this.http.post(this.apiRoot + val, { status: this.userAdvanceSearch.status, email: this.userAdvanceSearch.email, filterWithin: this.filterQuery, name: this.userAdvanceSearch.name, userTypeNo: this.authenticationService.getCurrentUserType().userTypeNo }, options).subscribe((res: any) => {      val === 'pdf' ? this.blob = new Blob([res], { type: 'application/pdf' }) : this.blob = new Blob([res], { type: 'text' });      const downloadURL = window.URL.createObjectURL(res);      const link = document.createElement('a');      link.href = downloadURL;      val === 'pdf' ? link.download = 'users.pdf' : link.download = 'users.csv';      link.click();      window.URL.revokeObjectURL(downloadURL);      this.spinner.hide();    });  }这按原样工作,但如果可能的话,我希望它更干净、更短。
查看完整描述

2 回答

  • 2 回答
  • 0 关注
  • 132 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信