WishMeLz

生活其实很有趣

qrcode

                import QRCode from 'qrcode'
                let canvas:any = document.getElementById('canvas')
                QRCode.toCanvas(
                    canvas,
                    'text',
                    { width: 150 },
                    function (error) {
                        console.log(error)
                    },
                )
      let myCanvas = this.$refs.canvas
      let ctx = myCanvas.getContext('2d')
      // 在Canvas画布 添加图片
      let img = new Image()
      img.crossOrigin = 'Anonymous';//解决Canvas.toDataURL 图片跨域问题
      img.src = this.logoUrl;
      img.onload = ()=>{
        //第一个设置的元素,第二三是位置,后面两个是宽和高
        //居中的位置计算为 (二维码宽度-img宽度)/2
        let codeWidth = (this.canvasWidth *0.75)/2
        let codeHeight = (this.canvasHeight * 0.75)/2
        ctx.drawImage(img, codeWidth, codeHeight,this.canvasWidth*0.25,this.canvasHeight*0.25)
      }