使用方法
在 script 中引入组件
import tkiQrcode from "@/components/tki-qrcode/tki-qrcode.vue"import '@/utils/ican-H5Api.js';export default {components: {tkiQrcode},data() {return {ifShow: true,val: 'dsfafaf', // 要生成的二维码值size: 260, // 二维码大小unit: 'upx', // 单位loadMake: true, // 组件加载完成后自动生成二维码src: '', // 二维码生成后的图片地址或base64invite: {}};},onLoad() {this.isLogin(true);this.getQrcode();},methods: {qrR(res) {this.src = res;console.log(this.src);},paste(value) {uni.setClipboardData({data: value,success() {uni.showToast({title: '复制成功'});}});},saveImg() {uni.showToast({title: '请截图保存',icon: 'none'})},getQrcode() {var me = this;// y请求接口 把要生成二维码的内容 赋值给 valthis.get('/api/user/url').then(res => {if (res.code == 0) {me.invite = res.data;me.val = res.data.url;// this.$refs.qrcode._makeCode(me.val);}});}}}
在 template 中使用
<tki-qrcode v-if="ifShow" ref="qrcode" :val="val" :size="size" :onval="true" :loadMake="loadMake" :usingComponents="true" @result="qrR" />
