vue axios 下载 获取文件名 filename 后端返回

const downloadRow = (row) => {
	importConfigApi.downloadTemplate(row.id, 'blob').then((res) => {
		console.log(res)
		// let fileName = ''
		let fileName = decodeURI(res.headers['content-disposition'].split(';')[2].split('filename*=')[1].split("''")[1])
		console.log(fileName)
		let url = window.URL.createObjectURL(new Blob([res.data]))
		let link = document.createElement('a')
		link.style.display = 'none'
		link.href = url
		link.id = 'Adownload'
		link.setAttribute('download', `${fileName}`)
		document.body.appendChild(link)
		link.click()
	})
}

你可能感兴趣的:(vue.js,javascript,前端)