<script setup>
import QRcode from "qrcode";
import { ref, reactive, onMounted } from "vue";
const qrcodeCanvas = ref("");
const text = ref("");
const changeText = () => {
if (text.value == "") {
alert("文本内容不能为空");
} else {
createQR();
}
};
const createQR = () => {
QRcode.toCanvas(
qrcodeCanvas.value,
text.value,
{
width: 200,
color: {
dark: "#000000",
light: "#ffffff",
},
}
);
};
</script>
<template>
<div class="test">
<input type="text" placeholder="输入链接或文本" v-model="text" /><button
@click="changeText()"
>
生成二维码
</button>
<div class="qrcode">
<canvas ref="qrcodeCanvas"> </canvas>
</div>
</div>
</template>
<style scoped>
canvas {
border: 1px solid;
}
</style>