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

实现5*5正方形网格x轴和y轴显示对应数值组件封装

实现5*5正方形网格x轴和y轴显示对应数值组件封装

需求:按5*5的正方形网格,根据目标数据的x和y轴值显示对应的文字,实现效果图如下:(当前目标数值:x=2,y=2)

在这里插入图片描述

代码如下:

<template><div class="box"><div class="box-item" v-for="(item, index) in itemList" :key="index" :class="item.className">{{ (x === item.x && y === item.y) ? item.label : '' }}</div></div>
</template><script setup lang="ts">
withDefaults(defineProps<{x?: number,y?: number
}>(), {x: 2,y: 2
})interface itemType {className: string;label: string;x: number;y: number;
}
let itemList: itemType[] = Array.from({ length: 25 }).map((_, index) => {let result = {className: '',label: '中',x: 0,y: 0}if ([3, 4, 8, 9, 14].includes(index)) {result.className = 'blue'result.label = '高'} else if ([10, 15, 16, 20, 21].includes(index)) {result.className = 'orange'result.label = '低'}result.className += ` xy-${index}`return result
})
let Y = 10
for (let j = 0; j < 25; j += 5) {for (let i = j; i < j + 5; i++) {if ([0, 5, 10, 15, 20].includes(i)) {itemList[i].x = 2} else {itemList[i].x = itemList[i - 1].x + 2}itemList[i].y = Y}Y -= 2
}
</script><style lang="scss" scoped>
.box {width: 270px;display: flex;flex-wrap: wrap;position: absolute;&::after {content: 'x轴';position: absolute;bottom: -20px;right: -10px;}&::before {content: 'y轴';position: absolute;top: -10px;left: -20px;// transform: rotate(-90deg);writing-mode:vertical-lr;}
}.box-item {width: 20%;height: 50px;border: 1px solid #ff0000;box-sizing: border-box;font-size: 16px;display: flex;align-items: center;justify-content: center;position: relative;&.xy-0::after {content: '10';position: absolute;left: -20px;}&.xy-5::after {content: '8';position: absolute;left: -20px;}&.xy-10::after {content: '6';position: absolute;left: -20px;}&.xy-15::after {content: '4';position: absolute;left: -20px;}&.xy-20::after {content: '2';position: absolute;left: -20px;}&.xy-20::before {content: '2';position: absolute;bottom: -20px;}&.xy-21::before {content: '4';position: absolute;bottom: -20px;}&.xy-22::before {content: '6';position: absolute;bottom: -20px;}&.xy-23::before {content: '8';position: absolute;bottom: -20px;}&.xy-24::before {content: '10';position: absolute;bottom: -20px;}
}.blue {background-color: skyblue;
}.orange {background-color: orange;
}
</style>
http://www.lryc.cn/news/110693.html

相关文章:

  • 基于Matlab实现图像压缩技术(附上完整源码+图像+程序运行说明)
  • 棒球联盟对于市场发展规划·棒球1号位
  • ansible控制主机和受控主机之间免密及提权案例
  • flink1.17 eventWindow不要配置processTrigger
  • Python导出SqlServerl数据字典为excel
  • PB:DDE服务器函数
  • awk经典实战、正则表达式
  • Python脚本-时间盲注
  • 面试总结-Redis篇章(十)——Redis哨兵模式、集群脑裂
  • el-table那些事
  • kubernetes(一)
  • 计算机网络(6) --- https协议
  • (三)Node.js - 模块化
  • 502 bad gateway报错
  • Flink学习教程
  • flutter开发实战-实现音效soundpool播放音频及控制播放暂停停止设置音量
  • Sequence 2023牛客暑期多校训练营6 E
  • 【ASP.NET MVC】使用动软(二)(10)
  • STM32入门学习之独立看门狗(IWDG)
  • 抖音seo矩阵系统源码搭建开发详解
  • 2685. 统计完全连通分量的数量;2718. 查询后矩阵的和;1600. 王位继承顺序
  • SpringBoot统一功能处理(AOP思想实现)(统一用户登录权限验证 / 异常处理 / 数据格式返回)
  • git stash 用法
  • 生鲜蔬果小程序的完整教程
  • De Bruijin序列与魔术(二)——魔术《De Bruijin序列》
  • ARCGIS地理配准出现的问题
  • redis原理 6:小道消息 —— PubSub
  • Android Studio 的Gradle版本修改
  • Redis的部分面试题
  • 单通道 6GSPS 16位采样DAC子卡模块--【资料下载】