//官网地址
http://html2canvas.hertzen.com/
//微信小程序基于base64生成二维码插件地址
https://github.com/Pudon/weapp-qrcode
//安装
Install NPM
npm install --save html2canvas
Install Yarn
yarn add html2canvas
//页面引入
import html2canvas from 'html2canvas';
// 本页面二维码生成方法
import qrcode from '../../utils/weapp-qrcode.js'
//data数据
data() {
return {
haiBa:false,
canvasImg: {
img: '',
name: '',
erWeima: ''
}
}
}
onLoad(e) {
// 生成二维码
let erCode = window.location.href
let params = erCode // 二维码参数
var imgData = qrcode.drawImg(params, {
typeNumber: 4, // 密度
errorCorrectLevel: 'L', // 纠错等级
size: 800, // 白色边框
})
this.canvasImg.erWeima = imgData
},
methods: {
// canvas海报
generatorImage() {
html2canvas(this.$refs.canDiv).then(canvas => {
// uni.showLoading({
// title: '生成中...'
// })
// console.log("canvas", canvas.toDataURL());
this.imgsBox = canvas.toDataURL() //base64字符串 放到图片标签上
// uni.hideLoading()
});
},
// 生成分享
shareBtn() {
this.haiBa = true
uni.showLoading({
title: '生成中...'
})
setTimeout(() => {
uni.hideLoading()
this.generatorImage()
this.$refs.popupCan.open()
this.haiBa = false
}, 500)
},
}