vue + axios get下載文件

exportExcelList(){
  this.pathUrl = 'admin/content/excel?token=' + localStorage['token'] + '&ex_type=article_stats' + 
  '&start_time=' + this.st_time + '&end_time=' + this.en_time;
				this.axios({
					method: 'get',
					url: this.pathUrl,
					responseType: 'blob'
				}).then((res) => {
					if(res.data.type == 'application/vnd.ms-excel') {
						if(!res) {
							return
						}
						let url = window.URL.createObjectURL(res.data);
						let link = document.createElement('a');
						link.style.display = 'none';
						link.href = url;
						link.setAttribute('download', 'product.xls');
						document.body.appendChild(link);
						link.click();
						this.$Notice.success({
							title: '提示',
							desc: '導出成功'
						});
					}else{
						this.$Notice.error({
							title: '提示',
							desc: '導出失敗'
						})
					}
				})
			},
相關文章
相關標籤/搜索