前端生成二维码并下载

Posted by Xiaosa's Blog on December 1, 2020
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
    import QRCode from 'qrcode'

        /**
         * @param {String} url  qrcode content
         * @param {String} name  qrcode file name
         * */
        execDownload: function (content, name) {
            this.downloadLoading = true
            QRCode.toDataURL(content)
                .then(res => {
                    let a = document.createElement("a");
                    a.href = res
                    a.download = name;
                    a.click();
                    this.$message && this.$message('下载成功')
                })
                .catch(err => {
                    console.error(err)
                }).finally(() => {
                    this.downloadLoading = false
                }
            )
        },