java+vue生成二維碼(沒使用qrcode插件)

一、前端

1、主要是img

<div v-if="this.content !== ''"><img :src="this.content" style="width: 100px; height: 100px;"></div>

2、方法:請求後臺獲取圖片流

async jointTable(){
    const axios = require('axios');
    if(this.dataForm !== '' && this.dataForm != null){
        axios({
            method: 'get',
            url: '/signin-app/signin/dy-img/qr',
            params: {
                idCard:this.dataForm.idCard
            },
            responseType: 'arraybuffer'
            }).then(response => {
                if (response.data) {
                    let img = 'data:image/png;base64,'+ btoa(new Uint8Array(response.data).reduce((data, byte) => data + String.fromCharCode(byte), ''));
                    this.content = img;
                }else{
                    this.content = ''
                }
            })
    }
},

二、後端

發佈了31 篇原創文章 · 獲贊 9 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章