网页获取微信信息——js使用插件生成二维码(1)

js使用插件生成二维码:

一、安装依赖:

npm i qrcodejs2 -S

二、放置二维码的容器,需要给一个ref

<div class="QRcodeCon">
    <!-- 放置二维码的容器,需要给一个ref -->
    <div id="qrcode" ref="qrcode"></div>
</div>

三、设置显示样式:

.QRcodeCon {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        #qrcode {
            width: 200px;
            height: 200px;
            border: 1px solid #ccc;
        }
    }

四、生成二维码

created() {
        this.wxLogin();
    },

    // 组件方法
    methods: {
        wxLogin() {
            this.qrcode =
                'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx7e31324eb53276f9&redirect_uri=http%3A%2F%2F10.86.19.116%3A8090%2F%2FwxAuth%2FcallBack&response_type=code&scope=snsapi_userinfo&state=123&connect_redirect=1#wechat_redirect';
            // 使用$nextTick确保数据渲染
            this.$nextTick(() => {
                this.crateQrcode();
            });
        },
        // 生成二维码
        crateQrcode() {
            this.qr = new QRCode('qrcode', {
                width: 200,
                height: 200, // 高度
                text: this.qrcode, // 二维码内容
                //colorDark: 'yellow',
                //colorLight: 'red',
                correctLevel: QRCode.CorrectLevel.H,
            });
        },
    }

五、完成显示到页面

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值