vue3+ts 分享海报

news/2024/10/22 11:38:09/

在这里插入图片描述

安装依赖1. npm install html2canvas --save
<div class="flex-box"><div><div v-for="(item,index ) in  from.list" :key="index" @click="actvieFuntion(index)"><div>{{item}}</div><div :class="from.activeIndex == index?'box':'box-1'"></div></div></div><div class="left"><div class="">模板-{{from.activeIndex+1}}</div><div class="border-mo" ><div id="CodeImgBase64"><div class="b-p-i"><div class="bg"><div class="tutle"><div class="text">iQOO 11S 16GB+1TB 传奇版超算独显芯片|2K 144Hz E6 全感屏|第二代骁龙8|200W 超快闪充|索尼定制 VCS IMX866</div></div><div class="to-moeny"><span class="c-o"></span><span>8999.00</span><span class="y-m">原价9999.00</span></div><div class="img-w-h"><img src=".././../../static/code.png" alt=""></div></div></div></div></div><div class="b-l"><el-button type="primary" @click="createPoster">下载海报</el-button></div></div>
</div>
<script lang="ts" setup>import html2canvas from "html2canvas"import {ref,reactive} from 'vue'const dialogVisible = ref(true)var from = reactive({list: ['模板1', '模板2', '模板3'],activeIndex: 0,posterImg: '',})const actvieFuntion = (num: any) => {from.activeIndex = num}const createPoster = ()=> {// 生成海报const domObj = document.getElementById("CodeImgBase64")//显示海报html2canvas(domObj, {useCORS: true,allowTaint: false,logging: false,letterRendering: true,onclone(doc:any) {let e = doc.querySelector("#CodeImgBase64");e.style.display = "block";console.log(doc)}}).then((canvas:any)=> {// 在微信里,可长按保存或转发var a = canvas.toDataURL("image/png");console.log(a)});}
</script>
<style scoped lang="scss">.dialog-footer button:first-child {margin-right: 10px;}.flex-box {display: flex;.box {width: 200px;height: 300px;border-radius: 10px;border: 3px solid #00aa00;}.box-1 {width: 200px;height: 300px;border-radius: 10px;border: 3px solid #aaaaaa;}.left {margin-left: 100px;.border-mo {width: 400px;height: 600px;border: 3px solid #aaaaaa;border-radius: 10px;}.b-l {width: 400px;text-align: center;margin-top: 30px;}}#CodeImgBase64{width: 400px;height: 600px;background-color: #ffffff;border-radius: 10px;}.b-p-i{width: 350px;height: 550px;background-color: #dcdcdc;margin: auto;border-radius: 10px;position: relative;top: 10px;}.bg{background-image: url('../../../static/phone.png');background-repeat: no-repeat;width: 350px;height: 400px;background-size: cover;margin: auto;border-radius: 10px;.tutle{position: relative;top: 328px;background: rgba(#000, 0.4);margin: auto;color: #fff;border-radius: 0px 0px 10px 10px;.text{width: 340px;margin: auto;font-size: 13px;}}.to-moeny{position: relative;top: 338px;left: 20px;font-size: 20px;font-weight: bold;color:red;.c-o{font-size: 12px;color:red;margin-right: 2px;}}.y-m{font-size: 10px;margin-left: 5px;color: #aaaaaa;text-decoration: line-through;font-weight: 400;}.img-w-h{position: relative;top: 358px;width: 70px;margin: auto;img{width: 70px;height: 70px;}}}}
</style>

http://www.ppmy.cn/news/1099102.html

相关文章

Revit SDK 介绍:PrintLog 打印日志

前言 这个例子介绍了如何使用打印相关的事件。 内容 事件机制也是老生常谈了&#xff0c;Revit 提供了大量的可供注册的事件&#xff1a;Revit API&#xff1a;Events 事件总览 注册和 print 相关的事件&#xff1a; // IExternalApplication.OnStartup m_eventsReactor …

单片机电子元器件-按键

电子元器件 按键上有 四个引脚 1 2 、 3 4 按下之后 导通 1 3 、 2 4 初始导通 通常按键开关为机械弹性开关&#xff0c;开关在闭合不会马上稳定的接通&#xff0c;会有一连串的抖动 抖动时间的长短有机械特性来决定的&#xff0c;一般为5ms 到10 ms 。 消抖的分类 硬件消…

深浅拷贝与赋值

数据类型 数据类型 在JavaScript中&#xff0c;数据类型有两大类。一类是基本数据类型&#xff0c;一类是引用数据类型。 基本数据类型有六种&#xff1a;number、string、boolean、null、undefined、symbol。 基本数据类型存放在栈中。存放在栈中的数据具有数据大小确定&a…

【Python 程序设计】Python 中的类型提示【06/8】

目录 一、说明 二、什么是动态类型&#xff1f; 2.1 为什么要使用类型提示&#xff1f; 2.2 局限性 三、基本类型提示 3.1 声明变量的类型 3.2 函数注释 四、Python 中的内置类型 4.1 原子类型与复合类型 五、函数注释 5.1 如何指定函数的参数类型和返回类型 5.2 在函数签名中…

Jdk1.7之ConcurrentHashMap源码总结

文章目录 一、常见属性1. 初始化容量2. 加载因子3. 并发级别 二、重要方法1. 构造方法2. ConcurrentHashMap#put方法2.1 ConcurrentHashMap#put#ensureSegment2.2 ConcurrentHashMap#Segment#put2.2.1 Segment#put#scanAndLockForPut2.2.2 Segment#put#rehash 3. ConcurrentHas…

CentOS 7 调优之周期性的访问中断

文章目录 背景问题描述原因分析解决方案相关版本 背景 操作系统版本&#xff1a;CentOS Linux release 7.6.1810 (Core) 操作系统镜像安装后&#xff0c;未进行任何调整。正常部署应用&#xff0c;应用在 CentOS 7.9 未出现过此类现象。 问题描述 问题描述&#xff1a;负载教…

软件源码开发,网络中的“摄像头”:运维监控系统

在日常生活中&#xff0c;我们不管是在大街小巷&#xff0c;还是在商场大厦都可以见到一个圆形或是方形带有镜片的“小盒子”&#xff0c;这个“小盒子”就是摄像头&#xff0c;摄像头作为一个能实时录制记录它能照到范围内的视频图像的工具&#xff0c;可以在丢失物品、抓捕坏…

jenkins如何请求http接口及乱码问题解决

文章目录 1.插件安装2.请求pipline语法3.插件方式实现4.乱码问题解决5.值得注意 1.插件安装 需要安装HTTP Request 插件&#xff1b;安装方式不介绍。 2.请求pipline语法 官网链接&#xff0c;上面有详细语法&#xff1a;https://plugins.jenkins.io/http_request/ 附一个d…