2023-03-02 02:46:16 +00:00
|
|
|
<docs>
|
|
|
|
---
|
|
|
|
order: 6
|
|
|
|
title:
|
|
|
|
zh-CN: 下载二维码
|
|
|
|
en-US: Download QRCode
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
下载二维码的简单实现。
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
A way to download QRCode.
|
|
|
|
</docs>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<a-qrcode ref="qrcodeCanvasRef" value="http://www.antv.com" />
|
|
|
|
<br />
|
|
|
|
<br />
|
|
|
|
<a-button type="primary" @click="dowloadChange">Downlaod</a-button>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import { defineComponent, ref } from 'vue';
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
setup() {
|
|
|
|
const qrcodeCanvasRef = ref();
|
|
|
|
const dowloadChange = async () => {
|
2023-03-03 06:56:23 +00:00
|
|
|
const url = await qrcodeCanvasRef.value.toDataURL();
|
2023-03-02 02:46:16 +00:00
|
|
|
const a = document.createElement('a');
|
|
|
|
a.download = 'QRCode.png';
|
|
|
|
a.href = url;
|
|
|
|
document.body.appendChild(a);
|
|
|
|
a.click();
|
|
|
|
document.body.removeChild(a);
|
|
|
|
};
|
|
|
|
return {
|
|
|
|
dowloadChange,
|
|
|
|
qrcodeCanvasRef,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|