1. 复制文本
copyText(msg) {
let copyInput = document.createElement('input');
document.body.appendChild(copyInput);
copyInput.setAttribute('value', msg);
copyInput.select();
document.execCommand('Copy');
this.$message({ message: '复制成功', type: 'success' });
copyInput.remove();
}
2. 下载流
// 下载流 stream是流文本,filename 是 将要转化成文件的文件名
downloadByStream (stream, filename) {
const blob = new Blob([stream])
const eLink = document.createElement('a')
eLink.download = filename
eLink.style.display = 'none'
eLink.href = URL.createObjectURL(blob)
document.body.appendChild(eLink)
eLink.click()
URL.revokeObjectURL(eLink.href)
document.body.removeChild(eLink)
}
用法:this.downloadByStream(res.data, '零售订单导出')
3.