后端返回二维码前端展示

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));

你可能感兴趣的:(vue,前端,javascript,开发语言)