简述:
文本不换行,超出显示省略号,两种提示方式,title提示和气泡提示
气泡提示不足:当内容没超过一行,也会出现气泡提示。觉得不如Element-UI的table组件好用。
若有简单有效的解决方案,还请告知哦^_^
<Table border :columns="tableColumn" :data="tableData"></Table>
mounted() {
this.initTableColumn('tableColumn')
},
methods: {
initTableColumn(columnName) {
// 提示一:title提示
for (let i = 0; i < this[columnName].length; i++) {
if (!this[columnName][i].render) {
this.$set(this[columnName][i], 'ellipsis', true)
this.$set(this[columnName][i], 'render', (h, params) => {
return h('span', {attrs: {title: params.row[params.column.key]}}, params.row[params.column.key])
})
}
}
// title提示
for (let i = 0; i < this[columnName].length; i++) {
if (!this[columnName][i].render) {
this.$set(this[columnName][i], 'render', (h, params) => {
return h('div', [
h('span', {
style: {
display: 'inline-block',
width: '100%',
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap'
},
domProps: {
title: params.row[params.column.key]
}
}, params.row[params.column.key])
])
})
}
}
// 提示二:气泡提示
for (let i = 0; i < this[columnName].length; i++) {
if (!this[columnName][i].render) {
this.$set(this[columnName][i], 'ellipsis', true)
this.$set(this[columnName][i], 'render', (h, params) => {
return h('Tooltip', {
props: { placement: 'top' }
}, [
params.row[params.column.key],
h('span', { slot: 'content', style: { whiteSpace: 'normal', wordBreak: 'break-all' } }, params.row[params.column.key])
])
})
}
}
}
}