vue对比功能,实现竖向table,可多列数据对比

news/2024/9/23 9:09:58/

一、实现效果

二、具体代码

        1、页面代码

<template><div class="app-container"><el-row><!--列表选择--><el-col :span="6" :xs="24"><div class="tac"><div style="display: inline-block; margin-bottom: 28px;margin-top: 8px">请选择奶粉A:</div><el-select v-model="queryParams.milikAId" clearable filterable placeholder="请选择"style="margin-right: 10px"><el-optionv-for="item in milkList":key="item.milk_powder_id":label="item.milk_powder":value="item.milk_powder_id"></el-option></el-select></div></el-col><el-col :span="6" :xs="24"><div class="tac"><div style="display: inline-block; margin-bottom: 28px;margin-top: 8px">请选择奶粉B:</div><el-select v-model="queryParams.milikBId" clearable filterable placeholder="请选择"style="margin-right: 10px"><el-optionv-for="item in milkList":key="item.milk_powder_id":label="item.milk_powder":value="item.milk_powder_id"></el-option></el-select></div></el-col><el-col :span="6" :xs="24"><div class="tac select-group"><div style="display: inline-block; margin-bottom: 28px; margin-top: 8px;">请选择国标:</div><el-select v-model="queryParams.nationalStandardId" clearable filterable placeholder="请选择"style="margin-left: 10px;"><el-optionv-for="item in milkStandardList":key="item.nationalStandardId":label="item.nationalStandard":value="item.nationalStandardId"></el-option></el-select></div></el-col><el-col :span="6" :xs="24" style="display: inline-block"><el-button type="success" plain @click="getTriggerCompare">确定-开始对比</el-button></el-col><div><contrastComp :contrast="contrast" :column="column"/></div></el-col></el-row></div>
</template>
<script>import contrastComp from '@/components/contrast'const contrast = Object.freeze([{img: 'https://img30.360buyimg.com/popshop/jfs/t1/243281/34/3214/2565/65a618c5F88f336b0/39e3e12f7ad20609.jpg',label: '汉兰达 2013款  2.7L 两驱5座紫金版',marketTime: '2013.06',width_height_length: '4795*1910*1760'},{img: 'https://img30.360buyimg.com/popshop/jfs/t1/243281/34/3214/2565/65a618c5F88f336b0/39e3e12f7ad20609.jpg',label: '汉兰达 2013款 2.7L 两驱7座紫金版',marketTime: '2013.06',width_height_length: '4795*1910*1760'},{img: 'https://img30.360buyimg.com/popshop/jfs/t1/243281/34/3214/2565/65a618c5F88f336b0/39e3e12f7ad20609.jpg',label: '汉兰达 2013款 2.7L 两驱7座探索版',marketTime: '2013.07',width_height_length: '4795*1910*1760'},{img: 'https://img30.360buyimg.com/popshop/jfs/t1/243281/34/3214/2565/65a618c5F88f336b0/39e3e12f7ad20609.jpg',label: '汉兰达 2012款 2.7L 两驱5座精英版',marketTime: '2012.06',width_height_length: '4795*1910*1730'}
])const column = Object.freeze([{label: '图片',prop: 'img'},{label: '名称',prop: 'label'},{label: '上市时间',prop: 'marketTime'},{label: '长*宽*高(mm)',prop: 'width_height_length'}
])export default {name: 'Index',components: {contrastComp},data() {return {contrast, // 对比数据,与平时使用相同column// 左侧名称和顺序}}
}
</script><style scoped>
.content {width: 100%;
}.yes-sir {width: 1000px;margin: 30px auto;border: solid 1px #eee;
}
</style>


 

        2、竖列组件代码

<template>
<div class="content">
<el-table
:data="targetArr"
:show-header="false"
stripe
border
style="width: 100%"
>
<el-table-column
prop="00"
align="center"
/>
<el-table-column
v-for="item in clumnArr"
:key="item"
:prop="String(item)"
align="center"
>
<template slot-scope="scope">
<div v-if="scope.row['00'] === '图片'">
<img :src="scope.row[scope.column.property]" alt="">
</div><span v-else>{{ scope.row[scope.column.property] }}</span>
</template>
</el-table-column>
</el-table>
</div>
</template><script>
export default {
name: 'Contrast',
props: ['contrast', 'column'],
data () {
return {
targetArr: [],
clumnArr: []
}
},
created () {
this.getChangeData()
},
methods: {
getChangeData () {
const clumnArr = [...new Array(this.contrast.length).keys()] // 改变数据,根据数据的长度生成数组,作为table的column的prop
const targetArr = [] // 数据数组
/**
* 下面则是将原数组转为合适数据
*/
const tableData = []
let objKey = []// 第一步将原数组中对象的key变为左侧需要展示的文字
this.contrast.forEach(ele => {
const obj = {}
this.column.forEach(item => {
obj[item.label] = ele[item.prop]
})
Object.keys(obj).forEach((item) => {
objKey.push(item)
})
tableData.push(obj)
})// 将所有的key值放到数组中
objKey = [...new Set(objKey)]// 根据左侧值遍历数组
for (let i = 0; i < objKey.length; i++) {
const obj = {}
for (let m = 0; m < tableData.length; m++) {
obj[m] = tableData[m][objKey[i]]
}
targetArr.push(obj)
}// 新增一个00作为左侧第一列的prop
targetArr.forEach((ele, index) => {
ele['00'] = objKey[index]
})this.targetArr = targetArr
this.clumnArr = clumnArr
}
}}
</script><style scoped>
.content{
width: 100%;
position: relative;
}</style>


 


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

相关文章

Python 天气预测

Python天气预测通常涉及到数据采集、数据预处理、选择和训练模型、以及预测和可视化等步骤。以下是使用Python进行天气预测的一般流程&#xff1a; 数据采集 使用爬虫技术从天气网站&#xff08;如Weather Underground、中国天气网等&#xff09;爬取历史天气数据&#xff0c…

mysql 如何查看一条SQL被回滚了

MySQL中查看一条SQL是否被回滚&#xff0c;通常不是一个直接的过程&#xff0c;因为MySQL本身并不提供直接的方式来追踪单个SQL语句的执行和回滚情况。但是&#xff0c;你可以通过一些方法和工具来间接地达到这个目的。下面&#xff0c;我将从多个角度介绍如何分析和判断SQL语句…

AItoolchain相关技术学习

AItoolchain主要模块包括&#xff1a; 模型转换&#xff1a;将深度学习模型转换为特定硬件平台可以识别和执行的格式。嵌入式运行环境&#xff1a;提供异构模型的运行库支持&#xff0c;确保模型在目标设备上的运行效率。性能验证&#xff1a;包括静态和动态性能评估&#xff…

死磕GMSSL通信-C/C++系列(一)

死磕GMSSL通信-C/C++系列(一) 最近再做国密通信的项目开发,以为国密也就简单的集成一个库就可以完事了,没想到能有这么多坑。遂写下文章,避免重复踩坑。以下国密通信的坑有以下场景 1、使用GMSSL guanzhi/GmSSL进行通信 2、使用加密套件SM2-WITH-SMS4-SM3 使用心得 ​…

ssm420基于JavaEE的企业人事管理信息系统的设计与实现论文

摘 要 现代经济快节奏发展以及不断完善升级的信息化技术&#xff0c;让传统数据信息的管理升级为软件存储&#xff0c;归纳&#xff0c;集中处理数据信息的管理方式。本企业人事管理信息系统就是在这样的大环境下诞生&#xff0c;其可以帮助管理者在短时间内处理完毕庞大的数据…

如何用flutter写一个好的登录页面

编写一个好的登录页面是构建用户友好且安全的移动应用的重要一步。下面是使用Flutter编写一个好的登录页面的一些建议和步骤&#xff1a; 1. 设计用户界面 1.简洁明了的布局&#xff1a;确保界面简洁明了&#xff0c;不要过分复杂&#xff0c;避免用户感到困惑。 2.清晰的输入框…

递归、搜索与回溯算法——递归

T04BF &#x1f44b;专栏: 算法|JAVA|MySQL|C语言 &#x1faf5; 小比特 大梦想 此篇文章与大家分享递归,搜索与回溯算法关于递归的专题 如果有不足的或者错误的请您指出! 目录 1.什么时候使用递归2.汉诺塔2.1解析2.2题解 3.合并两个有序链表3.1解析3.2题解 4.翻转链表4.1解析4…

CentOS 7软件安装全攻略:YUM命令详解与实战

在CentOS 7中&#xff0c;软件安装主要依赖于其强大的包管理器——YUM&#xff08;Yellowdog Updater Modified&#xff09;。YUM可以自动解决软件包之间的依赖关系&#xff0c;使得软件的安装、更新和卸载变得简单而高效。本文将详细介绍CentOS 7中软件安装的相关命令、选项和…