Skip to content

Commit 686a2b7

Browse files
committed
fix: ellipsis full length out '...'
1 parent be1fafa commit 686a2b7

File tree

2 files changed

+355
-353
lines changed

2 files changed

+355
-353
lines changed

src/components/Ellipsis/Ellipsis.vue

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<script>
22
import Tooltip from 'ant-design-vue/es/tooltip'
33
import { cutStrByFullLength, getStrFullLength } from '@/components/_util/StringUtil'
4-
/*
5-
const isSupportLineClamp = document.body.style.webkitLineClamp !== undefined;
4+
/*
5+
const isSupportLineClamp = document.body.style.webkitLineClamp !== undefined;
66
7-
const TooltipOverlayStyle = {
8-
overflowWrap: 'break-word',
9-
wordWrap: 'break-word',
10-
};
11-
*/
7+
const TooltipOverlayStyle = {
8+
overflowWrap: 'break-word',
9+
wordWrap: 'break-word',
10+
};
11+
*/
1212
1313
export default {
1414
name: 'Ellipsis',
@@ -37,27 +37,28 @@
3737
}
3838
},
3939
methods: {
40-
getStrDom (str) {
40+
getStrDom (str, fullLength) {
4141
return (
42-
<span>{ cutStrByFullLength(str, this.length) + '...' }</span>
42+
<span>{ cutStrByFullLength(str, this.length) + (fullLength > this.length ? '...' : '') }</span>
4343
)
4444
},
45-
getTooltip ( fullStr) {
45+
getTooltip (fullStr, fullLength) {
4646
return (
4747
<Tooltip>
4848
<template slot="title">{ fullStr }</template>
49-
{ this.getStrDom(fullStr) }
49+
{ this.getStrDom(fullStr, fullLength) }
5050
</Tooltip>
5151
)
5252
}
5353
},
5454
render () {
5555
const { tooltip, length } = this.$props
5656
const str = this.$slots.default.map(vNode => vNode.text).join('')
57-
const strDom = tooltip && getStrFullLength(str) > length ? this.getTooltip(str) : this.getStrDom(str)
57+
const fullLength = getStrFullLength(str)
58+
const strDom = tooltip && fullLength > length ? this.getTooltip(str, fullLength) : this.getStrDom(str, fullLength)
5859
return (
5960
strDom
6061
)
6162
}
6263
}
63-
</script>
64+
</script>

0 commit comments

Comments
 (0)