axios请求图片乱码
- 由于axios的默认responseType是:application/json, text/plain,会导致请求的图片显示乱码
指定 responseType: ‘blob’即可
function createImg(){const that = thisconst baseUrl = 'http://xxx.com/'axios({method: 'get',url: baseUrl + "/app/wx/getqrCode", // 请求地址data: {} , // 参数responseType: 'blob' // 表明返回服务器返回的数据类型}).then((res) => {let data = window.URL.createObjectURL(res.data)if (data) {that.setState({url: data})wxShare({// 图片需是绝对路径img: require('../../static/img/mine/qrcode.png').replace(/\.\.\//, baseUrl),url: `${baseUrl}/haibao.html`,desc: '瑜伽界',title: '分享领红包',})}})}
分享缩略图无效
- 图片域名需要和公众号对应的js安全域相同
- 返回的图片不能使用base64
- 必须使用绝对路径
