npm install qrcodejs2 --save

    1. <template>
    2. <div ref="qrcodeRef"></div>
    3. </template>
    1. <script lang='ts' setup>
    2. import { ref, defineComponent, onMounted } from 'vue';
    3. import QRCode from 'qrcodejs2-fixes';
    4. const qrcodeRef = ref<HTMLElement | null>(null);
    5. // 初始化生成二维码
    6. const initQrcode = () => {
    7. (qrcodeRef.value as HTMLElement).innerHTML = '';
    8. new QRCode(qrcodeRef.value, {
    9. text: `https://qm.qq.com/cgi-bin/qm/qr?k=RdUY97Vx0T0vZ_1OOu-
    10. X1yFNkWgDwbjC&jump_from=webapi`,
    11. width: 260,
    12. height: 260,
    13. colorDark: '#000000',
    14. colorLight: '#ffffff',
    15. });
    16. };
    17. // 页面加载时
    18. onMounted(() => {
    19. initQrcode();
    20. });
    21. </script>