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
70
71
72
73
74
75
76
77
78
79
| <template>
| <div class="qrcode-box">
| <div class="qrcode" ref="qrCodeUrl" alt=""></div>
| <div class="code" :class="isRed?'red':''">{{ showText }}</div>
| </div>
| </template>
|
| <script>
| import QRCode from "qrcodejs2";
|
| export default {
| name: "qrcode",
| props: {
| size: {
| type: Number,
| default: 300
| },
| qrUrl: {
| type: String,
| default: ""
| },
| showText: {
| type: String,
| default: ""
| },
| isRed: {
| type: Boolean,
| default: false
| }
| },
| data() {
| return {
| myChart: null
| };
| },
| computed: {},
| mounted: function() {
| this.creatQrCode();
| },
| beforeDestroy() {},
| methods: {
| creatQrCode() {
| var qrcode = new QRCode(this.$refs.qrCodeUrl, {
| text: this.qrUrl, // 需要转换为二维码的内容
| width: this.size,
| height: this.size,
| colorDark: "#000000",
| colorLight: "#ffffff",
| correctLevel: QRCode.CorrectLevel.H
| });
| }
| }
| };
| </script>
|
| <style scoped>
| .qrcode-box {
| display: flex;
| flex-direction: column;
| align-items: center;
| background: #fff;
| width: 100%;
| height: 100%;
| }
| .qrcode {
| width: 100%;
| height: 100%;
| display: block;
| }
| .code {
| text-align: center;
| font-size: 24px;
| margin-top: 10px;
| }
| .red {
| color: red;
| font-size: 12px;
| }
| </style>
|
|