当前位置: 首页 > news >正文

uniapp canvas vue3 ts实例

<template><view><canvas canvas-id='canvas-test' class="canvas-test"></canvas></view>
</template><script setup lang="ts">//封装的jsimport libs from '@/libs';//重点引入的import type { ComponentInternalInstance } from "vue";import { getCurrentInstance } from 'vue';const {proxy} = getCurrentInstance() as ComponentInternalInstance;const imgHttp = 'xxx/imgs/'onLoad(()=>{drawPoster();});const drawPoster = ()=>{const ctx = uni.createCanvasContext('canvas-test', proxy);return new Promise(async(r,j)=>{//绘制背景图await drwaBg(ctx);ctx.draw();})};const drwaBg = (ctx:any) : Promise<string>=>{return new Promise(async(r)=>{ctx.beginPath();let cWidth = uni.upx2px(750) //宽let cHeight = uni.upx2px(1362) //高const bgImgUrl = await libs.downloadFile(`${imgHttp}sell-save-bg.png`);ctx.drawImage(bgImgUrl,0,0,cWidth,cHeight);ctx.closePath();r(ctx);});};
</script><style lang="less" scoped>.canvas-test{width: 750rpx;height: 1362rpx;}
</style>
http://www.lryc.cn/news/386982.html

相关文章:

  • 网络构建关键技术_3.SDN技术
  • 【高性能服务器】单进程服务器
  • 任意密码重置漏洞
  • synchronized关键字和ReentrantLock在不同jdk版本中性能哪个高?该怎么选择呢?
  • 【旭日x3派】部署官方yolov5全流程
  • java LinkedList 怎么保证线程安全
  • uniapp+vue3开发微信小程序踩坑集
  • 办公软件WPS与Office的区别
  • [数据集][目标检测]睡岗检测数据集VOC+YOLO格式3290张4类别
  • 使用Java编写网络爬虫
  • 生鲜水果行业wordpress主题
  • 3.3V到5V的负电源产生电路(电荷泵电压反相器)SGM3204输出电流0.2A封装SOT23-6
  • Excel 宏录制与VBA编程 —— 15、MsgBox参数详解
  • Kafka~消息发送过程与ISR机制了解
  • multiprocessing.Queue 多个进程生产和多个进程消费怎么处理
  • 配置 Python 解释器及虚拟环境
  • JeecgBoot中如何对敏感信息进行脱敏处理?
  • 【Docker】存储数据卷
  • 《昇思25天学习打卡营第12天 | 昇思MindSpore基于MindSpore的GPT2文本摘要》
  • 深入解析npm unpublish命令:使用场景与实践指南
  • 有趣的仿神经猫html5圈小猫游戏源码
  • Redis 7.x 系列【10】数据类型之有序集合(ZSet)
  • 操作系统-文件的物理结构(文件分配方式)
  • Spring Boot集成jsoup实现html解析
  • [240629] 阿里云揭秘其数据中心设计和自研网络,用于大语言模型训练 | Jina AI 发布最新的神经网络重排序模型
  • 【Docker0】网络更改
  • IDEA中导入Maven项目
  • px、em、rem、rpx 作用和用法详解
  • Linux 常用命令 - dd 【复制及转换文件内容】
  • 全网唯一免费无水印AI视频工具!