当前位置:首页 > IT技术 > Web编程 > 正文

url转二维码(js,qrcode)可以带logo
2021-09-17 11:48:30

 

 

 

import QRCode from 'qrcode'  
import { Image } from 'antd'




const [qrCodeImageUrl, setQrCodeImageUrl] = useState()




useEffect(() => {
    QRCode.toDataURL(document.location.href)
      .then((url) => {
        console.log(url)
        setQrCodeImageUrl(url)
      })
      .catch((err) => {
        console.error(err)
      })
  }, [])





                <Image
                  className="m-qrcode-img"
                  src={qrCodeImageUrl}
                  alt={'图片'}
                  preview={{
                    mask: '',
                  }}
                ></Image>

参考链接:https://www.npmjs.com/package/qrcode

 

 

 

带logo:

import QrCodeWithLogo from 'qr-code-with-logo'
import { Image } from 'antd'


const [qrCodeImageUrl, setQrCodeImageUrl] = useState()


  useEffect(() => {
    const image = new Image()
    QrCodeWithLogo.toImage({
      image,
      content: document.location.href,
      logo: {
        src: logo,
      },
    })
    image.id = 'm-img'
    image.style = "display:none;"
    document.body.appendChild(image)
    const imageDom = document.getElementById('m-img')
    setTimeout(() => {
      setQrCodeImageUrl(imageDom.src)
    })
  }, [])





                <Image
                  className="m-qrcode-img"
                  src={qrCodeImageUrl}
                  alt={'图片'}
                  preview={{
                    mask: '',
                  }}
                ></Image>

 

 

 

 

 

 

 

 
 
 
 

本文摘自 :https://blog.51cto.com/x

开通会员,享受整站包年服务立即开通 >