自适应宽度
记录
function getTextWidth(str: string) {
let width = 0
let html = document.createElement('span')
html.innerText = str
html.className = 'getTextWidth'
document.querySelector('body')?.appendChild(html)
width = document.querySelector('.getTextWidth')?.offsetWidth
document.querySelector('.getTextWidth')?.remove()
return width + 50
}
<el-table :data="NewData.list" style="width: 1500px" height="700" show-overflow-tooltip fit>
<el-table-column :prop="t.value" :fixed="i == 0" :sortable="i != 0" v-for="(t, i) in NewData.Title" :width="getTextWidth(t.Title || '')">
<template #header>
{{ t.Title }}
</template>
</el-table-column>
</el-table>