chenyc
2025-07-14 05c827fea632f004821cc746ba73880769fab7cd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<template>
    <div class="qrcode-container layout-pd">
        <el-card shadow="hover" header="qrcodejs2 二维码生成">
            <el-alert
                title="感谢优秀的 `qrcodejs2`,项目地址:https://github.com/davidshimjs/qrcodejs"
                type="success"
                :closable="false"
                class="mb15"
            ></el-alert>
            <div class="qrcode-img-warp">
                <div class="mb30 mt30 qrcode-img">
                    <div class="qrcode" ref="qrcodeRef"></div>
                </div>
                <el-button type="primary" size="default" @click="onInitQrcode">
                    <el-icon>
                        <ele-Refresh />
                    </el-icon>
                    重新生成
                </el-button>
            </div>
        </el-card>
    </div>
</template>
 
<script setup lang="ts" name="funQrcode">
import { onMounted, ref } from 'vue';
import QRCode from 'qrcodejs2-fixes';
 
// 定义变量内容
const qrcodeRef = ref();
 
// 初始化生成二维码
const initQrcode = () => {
    new QRCode(qrcodeRef.value, {
        text: `https://lyt-top.gitee.io/vue-next-admin-preview/#/login?t=${new Date().getTime()}`,
        width: 125,
        height: 125,
        colorDark: '#000000',
        colorLight: '#ffffff',
    });
};
// 重新生成
const onInitQrcode = () => {
    qrcodeRef.value.innerHTML = '';
    initQrcode();
};
// 页面加载时
onMounted(() => {
    initQrcode();
});
</script>
 
<style scoped lang="scss">
.qrcode-container {
    .qrcode-img-warp {
        text-align: center;
        .qrcode-img {
            display: flex;
            width: 100%;
            height: 125px;
            .qrcode {
                margin: auto;
                width: 125px;
                height: 125px;
            }
        }
    }
}
</style>