2 回答

TA貢獻(xiàn)1826條經(jīng)驗 獲得超6個贊
new Vue({
el: '#app',
data () {
return {
src: null
}
},
mounted () {
let self = this
fetch("https://thumbs.dreamstime.com/z/freely-accessible-examination-exposition-mosaic-ar-figures-mosaic-st-petersburg-russia-june-freely-accessible-119320551.jpg")
.then((response) => {
response.blob().then(blobResponse => {
let reader = new FileReader();
reader.readAsDataURL(blobResponse);
reader.onloadend = function() {
let base64data = reader.result;
let img = document.createElement('img')
img.src = base64data
self.$refs['img-container'].appendChild(img)
}
})
})
}
})
img {
height: 300px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<div ref="img-container"></div>
</div>

TA貢獻(xiàn)1847條經(jīng)驗 獲得超7個贊
請求的響應(yīng)類型(axios請求)應(yīng)該是?responseType: 'blob'
從服務(wù)器接收到數(shù)據(jù)后,我簡單地使用下面這行代碼生成一個DOM字符串,然后將其作為圖像標(biāo)簽的src:
const?imageUrl?=?window.URL.createObjectURL(new?Blob([response.data])) <img?:src="imageUrl?">
- 2 回答
- 0 關(guān)注
- 171 瀏覽
添加回答
舉報