今天整理一下前几天写的一个项目生成微信,支付宝二维码,今天把代码整合一下,以后可以再次翻阅;
使用vue-qriously生成二维码
**先安装qrcodejs2**
cnpm install --save qrcodejs2
components: {QRCode},
/*页面里有个标签展示二维码*/
<template>
<div id="qrcode" ref="qrcode" ></div>
</template>
<script>
import QRCode from 'qrcodejs2' // 引入qrcode
export default {
name : 'test',
methods: {
/**封装函数解析后端给的数据生成二维码*/
qrcode() {
let that = this;
let qrcode = new QRCode('qrcode', {
width: 370, // 设置宽度
height: 370, // 设置高度
text: https://qr.alipay.com/bax07401rgsvejezkiqd409d,//图片地址
})
},
/**在需要展示二维码的地方调用这个函数,
一定要加上 that.$nextTick(function () { }); 用于延迟执行一段代码*/
that.$nextTick(function () {
that.qrcode();
});
}
</script>
前端小白—的爬坑之路 ,如有不对之处请多指教