vue3使用el-table實現(xiàn)新舊數(shù)據(jù)對比的代碼詳解
更新時間:2023年12月03日 10:17:42 作者:許個愿~
這篇文章主要為大家詳細介紹了在vue3中使用el-table實現(xiàn)新舊數(shù)據(jù)對比,文中的示例代碼講解詳細,具有一定的參考價值,需要的小伙伴可以參考一下
效果圖(不同數(shù)據(jù)用紅色字體標出)
直接上代碼
<template> <el-dialog v-model="dialogVisible" title="數(shù)據(jù)對比" 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([]) // 打開彈出層 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實現(xiàn)新舊數(shù)據(jù)對比的代碼詳解的詳細內(nèi)容,更多關(guān)于vue3 el-table新舊數(shù)據(jù)對比的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Vue使用mounted和created時,this無法指向data中的數(shù)據(jù)問題
這篇文章主要介紹了Vue使用mounted和created時,this無法指向data中的數(shù)據(jù)問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-07-07Vue實施重新發(fā)布和軟件熱更新的經(jīng)驗分享
在Web應(yīng)用的開發(fā)周期中,版本管理和軟件熱更新是一個不可或缺的話題,隨著Vue.js框架的流行,越來越多的應(yīng)用程序選擇使用Vue來構(gòu)建前端,本文將探討在Vue應(yīng)用中實施重新發(fā)布和熱更新的最佳實踐,需要的朋友可以參考下2024-09-09vue.config.js中devServer.proxy配置說明及配置正確不生效問題解決
Vue項目devServer.proxy代理配置詳解的是一個非常常見的需求,下面這篇文章主要給大家介紹了關(guān)于vue.config.js中devServer.proxy配置說明及配置正確不生效問題解決的相關(guān)資料,需要的朋友可以參考下2023-02-02