64 lines
897 B
Vue
64 lines
897 B
Vue
<template>
|
|
<table>
|
|
<thead>
|
|
<tr v-for="(value, key, i) in getHeaders" :key="i">
|
|
<th>{{ key }}</th>
|
|
<th>{{ value }}</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr v-for="(value, key, i) in dataRows" :key="i+1">
|
|
<td>{{ key }}</td>
|
|
<td>{{ value }}</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
name: 'KeyValueTable',
|
|
props: {
|
|
dataRows: {
|
|
type: Object,
|
|
default: () => ({}),
|
|
},
|
|
header: {
|
|
type: Object,
|
|
default: () => ({}),
|
|
},
|
|
},
|
|
computed: {
|
|
getHeaders() {
|
|
const key = Object.keys(this.header)[0]
|
|
const value = this.header[key]
|
|
if (key && value) return { [key]: value }
|
|
|
|
return {}
|
|
},
|
|
},
|
|
}
|
|
</script>
|
|
|
|
<style scoped>
|
|
table {
|
|
width: 100%;
|
|
}
|
|
|
|
td, th {
|
|
border-bottom: solid #000 1px;
|
|
}
|
|
|
|
th {
|
|
font-weight: bold;
|
|
}
|
|
|
|
thead {
|
|
background: #f0f0f0;
|
|
}
|
|
|
|
tbody tr:nth-child(2n) {
|
|
background: #f0f0f0;
|
|
}
|
|
</style>
|