vue 接收回显文件流

2020-06-11  本文已影响0人  Augenstern___
_this.Axios.post('/Manage/SpuInfo/preview',
            {
             data
             },
             {
            responseType: "arraybuffer", 
        }).then(res => {
          return 'data:image/png;base64,' + btoa(
            new Uint8Array(res.data)
              .reduce((data, byte) => data + String.fromCharCode(byte), '')
          );
        }).then(data => {
          _this.previewImage = data //图片地址 <img src='data' />
     
        })

responseType: “arraybuffer”, 是必须的 下面 转自:https://www.jianshu.com/p/6705e2eabaa1

···axios.post(apiUrl, formdata, {responseType:'arraybuffer'}).then().catch();
axios 文档对responseType 的说明
`responseType` 表示服务器响应的数据类型,可以是 'arraybuffer', 'blob', 'document', 'json', 'text', 'stream'
默认的 responseType: 'json',
上一篇 下一篇

猜你喜欢

热点阅读