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显示弹窗

猜你喜欢

转载自blog.csdn.net/xiyan_yu/article/details/131582363
今日推荐