vue3实现canvas图片和div整合下载

图片加载完成事件中完成canvas函数的绘画。引入到图片加载事件所在的文件(父组件)中。新建一个文件放置所要整合的div。下载的图片已经生成div。在setup中的实现函数。
摘要由CSDN通过智能技术生成

在这里插入图片描述
下载的图片已经生成div
在这里插入图片描述
图片加载完成事件中完成canvas函数的绘画

        <el-image
          :src="
            locationIP +
            '/prod-api/get/detection/img/' +
            itemData.img_id +
            '?token=' +
            token
          "
          :load="htmlCanvas(itemData)"
        >
        </el-image>

新建一个文件放置所要整合的div

<template>
  <svg :width="context.elWidth" :height="context.elHeight">
    <foreignObject
      x="0"
      :y="0"
      :height="context.elHeight"
      :width="context.elWidth"
    >
        <div
        style="
          /* background: rgba(255, 255, 255, 1); */
          width: 100%;
         height: 500px;//后来察觉此高度无效
          color: black;
          font-weight: bold;
          font-size: 30px;
          border-radius: 10px;
          box-sizing: border-box;
          /* opacity: 0; */
          /* background:rgba(255, 255, 255, 0.6); */
          padding-bottom: 20px;
          overflow: hidden;
        "
      >
        <div
          style="
            width: 100%;
            background-color: rgba(121,180,242, 0.7);
            height: 80px;
            padding-left: 10px;
            border-top-left-radius: 10px;
            border-top-right-radius: 10px;
            line-height: 80px;
            text-align: center;
            color: #fff;
            display
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实现拓扑图可以使用 Vue3 和 Canvas 结合来完成。下面是一个简单的实现过程: 1. 首先,需要安装 Vue3 和 Canvas 库: ``` bash npm install vue@next npm install canvas --save ``` 2. 在 Vue3 中创建一个组件,用于渲染拓扑图。在组件中引入 Canvas 库: ``` javascript <template> <canvas ref="canvas"></canvas> </template> <script> import { onMounted, ref } from 'vue' import Canvas from 'canvas' export default { setup() { const canvasRef = ref(null) onMounted(() => { const canvas = canvasRef.value const ctx = canvas.getContext('2d') // 在这里进行绘制 }) return { canvasRef } } } </script> ``` 3. 在组件的 `onMounted` 钩子函数中,获取 Canvas 的上下文对象 `ctx`,并进行绘制。可以使用 Canvas 的 API 画出线条、圆形等形状,也可以使用外部库来绘制更复杂的图形。 4. 在绘制时,可以将节点和线条信息存储在数组中,以方便后续的更新和交互。例如: ``` javascript // 存储节点和线条信息的数组 const nodes = [ {x: 100, y: 100, r: 20, color: '#ff0000'}, {x: 200, y: 200, r: 30, color: '#00ff00'} ] const links = [ {source: 0, target: 1}, {source: 1, target: 2} ] // 绘制节点 nodes.forEach(node => { ctx.beginPath() ctx.arc(node.x, node.y, node.r, 0, Math.PI * 2) ctx.fillStyle = node.color ctx.fill() }) // 绘制线条 links.forEach(link => { const source = nodes[link.source] const target = nodes[link.target] ctx.beginPath() ctx.moveTo(source.x, source.y) ctx.lineTo(target.x, target.y) ctx.stroke() }) ``` 以上就是一个简单的 Vue3 和 Canvas 实现拓扑图的过程。需要注意的是,Vue3 的模板中不能直接使用 Canvas,需要通过 `ref` 引用实现。另外,绘制时需要注意节点和线条的位置信息,以及 Canvas 的坐标系。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值