方法一:
<template>
<view class="">
<view class="pc-container">
<image :src="imgurl" mode=""></image>
</view>
<view class="basecolor sharetext">長(zhǎng)按二維碼發(fā)送給代理即可邀請(qǐng)加入</view>
</view>
</template>
<script>
import $store from '@/store'
export default {
data() {
return {
imgurl:''
}
},
onLoad() {
uni.request({
url: 'http://api.woaidakele.cn/api/AddQrCode',
responseType: 'arraybuffer',
header: {
'Authorization': 'Bearer ' + $store.state.app.token
},
success: (res) => {
const arrayBuffer = res.data
this.imgurl = 'data:image/jpeg;base64,'+ uni.arrayBufferToBase64(arrayBuffer)
}
});
},
methods: {
},
}
</script>
方法二:
<template>
<view class="">
<view class="pc-container">
<image :src="imgurl" mode=""></image>
</view>
<view class="basecolor sharetext">長(zhǎng)按二維碼發(fā)送給代理即可邀請(qǐng)加入</view>
</view>
</template>
<script>
import $store from '@/store'
export default {
data() {
return {
imgurl:''
}
},
onLoad() {
uni.request({
url: 'http://api.woaidakele.cn/api/AddQrCode',
responseType: 'arraybuffer',
header: {
'Authorization': 'Bearer ' + $store.state.app.token
},
success: (res) => {
this.imgurl = 'data:image/jpeg;base64,' + this.arrayBufferToBase64(res.data)
}
});
},
methods: {
arrayBufferToBase64(buffer) {
var binary = ''
var bytes = new Uint8Array(buffer)
var len = bytes.byteLength
for (var i = 0; i < len; i++) {
binary += String.fromCharCode(bytes[i])
}
return window.btoa(binary)
}
},
}
</script>
responseType: 'arraybuffer' 這個(gè)響應(yīng)類型必須要寫