uniapp使用canvas绘图在app端背景和文字无法绘制

由于我要绘制的图片通过v-if控制的显示与隐藏,一开始dom上并没有canvas,导致背景和文字无法绘制,可通过绝对定位,不显示图片时,设置top将其移出可视页面,然后显示图片时再改top

<view class="my-canvas-box flex column justify-content-center align-items-center" :style="{top:showCode?0:'100%'}">
		<view class="flex justify-content-end" style="padding: 20rpx 20rpx 0; background: #fff; width: 570rpx;">
			<text class="iconfont icon-guanbi" @tap="showCode=false"></text>
		</view>
		<view class="" style="background-color: #fff;">
			<!-- #ifndef H5 -->
			<canvas class="my-canvas" canvas-id="mycanvas" :style="{ width: canvasW + 'px', height: canvasH + 'px' }"></canvas>
			<!-- #endif -->
			<!-- #ifdef H5 -->
			<view class="my-canvas  flex column justify-content-center align-items-center" :style="{ width: canvasW + 'px', height: canvasH + 'px' ,background:'#fff'}">
				<view class="font-size-32 font-600">{{title}}</view>
				<image :src="qrcode" mode="" style="width: 360rpx; height: 360rpx; margin-top: 30rpx;"></image>
				<image :src="imageurl" mode="" class="maskimg" v-if="isweixin"></image>
			</view>
			<!-- #endif -->
		</view>
		
		<!-- #ifdef H5 -->
		<button class="btn" @tap="save" v-if="!isweixin">保存图片</button>
		<button class="btn" v-else>长按保存图片</button>
		<!-- #endif -->
		<!-- #ifndef H5 -->
		<button class="btn" @tap="save">保存图片</button>
		<!-- #endif -->
		
		<view class="mask" @tap="showCode=false"></view>
</view>

部分css

.my-canvas-box{
  	width: 100%;
  	height: 100%;
  	background: rgba(0, 0, 0, 0.25);
  	position: fixed;
  	top: 0;
  	left: 0;
  	z-index: 99;
}

showCode为ture显示弹窗

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值