1: 调用后端接口,responseType设置为blob
const res = await axios.get('/xxx/xxx', {
responseType: 'blob',
});
// res 为二进制流
const binaryData = [];
binaryData.push(res);
this.QrUrl = window.URL.createObjectURL(new Blob(binaryData));
<img :src="QrUrl" style="width: 200px; height: 200px" />
2: 由于chrom 升级 不支持window.URL.createObjectURL()这种写法
会报错 Failed to execute 'createObjectURL' on 'URL': Overload resolution failed
需改为
const binaryData = [];
binaryData.push(res);
this.QrUrl = window.URL.createObjectURL(new Blob(binaryData));
后端返回二维码前端展示
于 2022-03-16 11:04:36 首次发布