<div class="img" ref="code">
<qrcode-vue :value="link" size="175" level="H" />
</div>
<p class="down" @click="code()">下载二维码</p>
import html2canvas from "html2canvas";
import QrcodeVue from "qrcode.vue";
components:{
QrcodeVue,
html2canvas,
},
code() {
html2canvas(this.$refs.code, {
backgroundColor: "#fff",
useCORS: true, // 第三个修改的地方
allowTaint: true, //允许跨域(默认false)
}).then((canvas) => {
let dataURL = canvas.toDataURL("image/jpg");
if (dataURL !== "") {
var a = document.createElement("a");
a.crossOrigin = "*";
a.download = "二维码.jpg";
a.href = dataURL;
a.click();
}
});
},
vue-生成二维码+下载二维码
最新推荐文章于 2024-09-03 08:34:52 发布