vue3使用el-table實現新舊數據對比的代碼詳解
更新時間:2023年12月03日 10:17:42 作者:許個愿~
這篇文章主要為大家詳細介紹了在vue3中使用el-table實現新舊數據對比,文中的示例代碼講解詳細,具有一定的參考價值,需要的小伙伴可以參考一下
效果圖(不同數據用紅色字體標出)
直接上代碼
<template> <el-dialog v-model="dialogVisible" title="數據對比" 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: '舊數據', name2: '新數據' } 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: '數據1', b: '數據2', c: '數據3' } objChange() } defineExpose({ compBtn }) </script> <style lang="scss" scoped></style>
以上就是vue3使用el-table實現新舊數據對比的代碼詳解的詳細內容,更多關于vue3 el-table新舊數據對比的資料請關注腳本之家其它相關文章!
相關文章
Vue使用mounted和created時,this無法指向data中的數據問題
這篇文章主要介紹了Vue使用mounted和created時,this無法指向data中的數據問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-07-07vue.config.js中devServer.proxy配置說明及配置正確不生效問題解決
Vue項目devServer.proxy代理配置詳解的是一個非常常見的需求,下面這篇文章主要給大家介紹了關于vue.config.js中devServer.proxy配置說明及配置正確不生效問題解決的相關資料,需要的朋友可以參考下2023-02-02