显示图片,但要求使用封装api,请求接口的形式。
this.$axios({
method: 'get',
url:'/api/common/download?fileName=/profile/lcw.png',
responseType:'blob' // res.data 是一个Blob对象
})
.then(res => {
this.src = URL.createObjectURL(res.data)
})
this.$axios({
method: 'get',
url:'/api/common/download?fileName=/profile/lcw.png',
responseType:'arraybuffer' // res.data是一个ArrayBuffer对象
})
.then(res => {
this.src = 'data:image/png;base64,' +
btoa(new Uint8Array(res.data).reduce(
(previousValue,currentValue) => previousValue + String.fromCharCode(currentValue), ''
))
})