mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-17 15:09:31 +00:00
qrcode 改为cdn
This commit is contained in:
34
components/QrCode.js
Normal file
34
components/QrCode.js
Normal file
@@ -0,0 +1,34 @@
|
||||
import BLOG from '@/blog.config'
|
||||
import { loadExternalResource } from '@/lib/utils'
|
||||
import { useEffect } from 'react'
|
||||
|
||||
/**
|
||||
* 二维码生成
|
||||
*/
|
||||
export default function QrCode({ value }) {
|
||||
useEffect(() => {
|
||||
let qrcode
|
||||
if (!value) {
|
||||
return
|
||||
}
|
||||
loadExternalResource(BLOG.QR_CODE_CDN, 'js').then(url => {
|
||||
const QRCode = window.QRCode
|
||||
qrcode = new QRCode(document.getElementById('qrcode'), {
|
||||
text: value,
|
||||
width: 256,
|
||||
height: 256,
|
||||
colorDark: '#000000',
|
||||
colorLight: '#ffffff',
|
||||
correctLevel: QRCode.CorrectLevel.H
|
||||
})
|
||||
console.log('二维码', qrcode, value)
|
||||
})
|
||||
return () => {
|
||||
if (qrcode) {
|
||||
qrcode.clear() // clear the code.
|
||||
}
|
||||
}
|
||||
}, [])
|
||||
|
||||
return <div id="qrcode"></div>
|
||||
}
|
||||
Reference in New Issue
Block a user