uni-app 网络图片转Base64

 
export default {
    data() {
        return {
            showImg : "", //显示图片地址
            coverImg : 'https://ossweb-img.qq.com/images/lol/web201310/skin/big10001.jpg' //网络图片地址
        }
    },
    onLoad() {
        this.urlTobase64(this.coverImg);
    },
    methods: {
        imageError: function(e) {
            console.error('image发生error事件,携带值为' + e.detail.errMsg)
        },
        urlTobase64(url) {
            let toBase64Url;
            uni.request({
                url: url,
                method: 'GET',
                responseType: "arraybuffer",
                success: async res => {
                    let base64 = wx.arrayBufferToBase64(res.data); //把arraybuffer转成base64
                    toBase64Url = 'data:image/jpeg;base64,' + base64; //不加上这串字符,在页面无法显示
                    console.log(toBase64Url);
                    this.showImg= toBase64Url;
                 }
             });
        },
    }
}

你可能感兴趣的:(uni-app 网络图片转Base64)