vue3使用el-table實(shí)現(xiàn)新舊數(shù)據(jù)對(duì)比的代碼詳解
效果圖(不同數(shù)據(jù)用紅色字體標(biāo)出)

直接上代碼
<template>
<el-dialog v-model="dialogVisible" title="數(shù)據(jù)對(duì)比" width="40%" :before-close="handleClose">
<div class="c-table">
<el-table :data="tableDataRecords" border max-height="700px">
<el-table-column width="160px" prop="type" label=""></el-table-column>
<el-table-column prop="column1" :label="name.name1"> </el-table-column>
<el-table-column prop="column2" :label="name.name2">
<template #default="scope">
<div v-if="scope.row.column1 == scope.row.column2">{{ scope.row.column2 }}</div>
<div style="color: red" v-else>{{ scope.row.column2 }}</div>
</template>
</el-table-column>
<template #empty>
<img src="@/assets/images/common/no-data.png" alt="" width="179" />
</template>
</el-table>
</div>
</el-dialog>
</template>
<script setup>
import { ref } from 'vue'
const name = {
name1: '舊數(shù)據(jù)',
name2: '新數(shù)據(jù)'
}
const obj1 = ref()
const obj2 = ref()
const obj3 = ref()
const objChange = () => {
console.log(obj1.value, obj2.value, obj3.value)
for (const key in obj3.value) {
if (obj3.value.hasOwnProperty(key)) {
const record = {
type: obj3.value[key] ?? '--',
column1: obj2.value[key] ?? '--',
column2: obj1.value[key] ?? '--'
}
tableDataRecords.value.push(record)
}
}
}
const tableDataRecords = ref([])
// 打開(kāi)彈出層
const dialogVisible = ref(false)
const compBtn = async (row, fileds) => {
tableDataRecords.value = []
dialogVisible.value = true
obj1.value = { a: '1', b: '2', c: '3' }
obj2.value = { a: '1', b: '2', c: '4' }
obj3.value = { a: '數(shù)據(jù)1', b: '數(shù)據(jù)2', c: '數(shù)據(jù)3' }
objChange()
}
defineExpose({
compBtn
})
</script>
<style lang="scss" scoped></style>以上就是vue3使用el-table實(shí)現(xiàn)新舊數(shù)據(jù)對(duì)比的代碼詳解的詳細(xì)內(nèi)容,更多關(guān)于vue3 el-table新舊數(shù)據(jù)對(duì)比的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Vue使用mounted和created時(shí),this無(wú)法指向data中的數(shù)據(jù)問(wèn)題
這篇文章主要介紹了Vue使用mounted和created時(shí),this無(wú)法指向data中的數(shù)據(jù)問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-07-07
Vue實(shí)施重新發(fā)布和軟件熱更新的經(jīng)驗(yàn)分享
在Web應(yīng)用的開(kāi)發(fā)周期中,版本管理和軟件熱更新是一個(gè)不可或缺的話(huà)題,隨著Vue.js框架的流行,越來(lái)越多的應(yīng)用程序選擇使用Vue來(lái)構(gòu)建前端,本文將探討在Vue應(yīng)用中實(shí)施重新發(fā)布和熱更新的最佳實(shí)踐,需要的朋友可以參考下2024-09-09
vue.config.js中devServer.proxy配置說(shuō)明及配置正確不生效問(wèn)題解決
Vue項(xiàng)目devServer.proxy代理配置詳解的是一個(gè)非常常見(jiàn)的需求,下面這篇文章主要給大家介紹了關(guān)于vue.config.js中devServer.proxy配置說(shuō)明及配置正確不生效問(wèn)題解決的相關(guān)資料,需要的朋友可以參考下2023-02-02
Vue-Luckysheet的使用方法及遇到問(wèn)題解決方法
Luckysheet ,一款純前端類(lèi)似excel的在線(xiàn)表格,功能強(qiáng)大、配置簡(jiǎn)單、完全開(kāi)源,這篇文章主要介紹了Vue-Luckysheet的使用方法,需要的朋友可以參考下2022-08-08
Vue項(xiàng)目前端部署詳細(xì)步驟(nginx方式)
Nginx(engine x)是一個(gè)高性能的HTTP和反向代理web服務(wù)器,是部署前端項(xiàng)目的首選,這篇文章主要給大家介紹了關(guān)于Vue項(xiàng)目前端部署(nginx方式)的相關(guān)資料,需要的朋友可以參考下2023-09-09
Vue3中依賴(lài)注入provide、inject的使用
這篇文章主要介紹了Vue3中依賴(lài)注入provide、inject的使用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-10-10
vue做移動(dòng)端適配最佳解決方案(親測(cè)有效)
這篇文章主要介紹了vue做移動(dòng)端適配最佳解決方案(親測(cè)有效),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-09-09

