html2canvas 绘制海报 框架uniapp

有时候,不是因为你没有能力,也不是因为你缺少勇气,只是因为你付出的努力还太少,所以,成功便不会走向你。而你所需要做的,就是坚定你的梦想,你的目标,你的未来,然后以不达目的誓不罢休的那股劲,去付出你的努力,成功就会慢慢向你靠近。

导读:本篇文章讲解 html2canvas 绘制海报 框架uniapp,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com,来源:原文

<!-- 海报 影藏位置 -->
			<div class="canDiv" ref="canDiv" v-show="haiBa">
				<view class="canDiv1">
					<!-- crossorigin ="anonymous" -->
					<img ref="imhBx" :src="canvasImg.img" mode=""></img>
				</view>
				<view class="canDiv2">{{canvasImg.name}}</view>
				<view class="canDiv3">
					<image :src="canvasImg.erWeima" mode=""></image>
				</view>
				<view class="canDiv4">长按图片保存到手机</view>
			</div>


            <view class="pl1" @click="shareBtn">
				<span class="iconfont foSiz20">&#xe6c4;</span>分享
			</view>

弹出层位置

<uni-popup ref="popupCan" type="center">
			<!-- <view class="" :style="{width:imgWidth,height:imgHeight}"> -->
			<view class="popImg">
				<!-- <view class="popImg" @click.stop="closeBtn"> -->
				<image class="imgPop" :src="imgsBox" mode="aspectFit" style="z-index: 1000;"></image>
			</view>
			<!-- </view> -->
		</uni-popup>

//官网地址
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)
			
			},
}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/144806.html

(0)
飞熊的头像飞熊bm

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!