uniapp中监听图片的头部
有些时候,我们需要监听图片的头部,比如说图灵码,通常是在头部携带一个id,id与码匹配来判断是否正确。
那怎么获取到header呢?
不使用img来直接显示
先通过request来请求图片,请求到图片以后显示在imag上。
此时,对相应的header进行监听,获取需要的内容。
header的监听没什么好说的,主要是图片的上获取和显示
export const getCaptcha = () => {
return new Promise((resolve, reject) => {
uni.request({
url: baseUrl + '/sys/captcha_text',
method: 'GET',
responseType: 'arraybuffer',
}).then(result => {
console.log(result.header);
resolve(result.data);
}).catch(error => {
reject(error)
});
});
};
转换
function doCaptchaGet() {
getCaptcha().then(result => {
let tmp = uni.arrayBufferToBase64(result);
captchaUrl.value = "data:image/png;base64," + tmp;
});
}
这样子就可以显示了
