Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. <template>
  2. <div class="text-ellipsis" :style="{height: textHeight,lineHeight: lineHeight}">
  3. <div class="ellipsis-before" :style="{height: textHeight}"></div>
  4. <div class="ellipsis-content">
  5. <template v-if="$slots.default">
  6. <slot></slot>
  7. </template>
  8. <template v-else>{{text}}</template>
  9. </div>
  10. <div class="ellipsis-after" :style="{top: '-'+lineHeight, height: lineHeight}">...</div>
  11. </div>
  12. </template>
  13.  
  14. <script>
  15. export default {
  16. props: {
  17. text: String,
  18. lineHeight: {
  19. type: String,
  20. default: "25px" // 行高,默认25px
  21. },
  22. row: {
  23. type: [String, Number],
  24. default: 2 // 截断行数,默认第二行进行截断
  25. }
  26. },
  27. computed: {
  28. textHeight() {
  29. let rows = parseInt(this.row);
  30. return `${parseInt(this.lineHeight) * (rows > 0 ? rows : 1)}px`;
  31. }
  32. }
  33. };
  34. </script>
  35.  
  36. <style scoped>
  37. /* 单行文本截断 */
  38. .text-ellipsis__single {
  39. width: 200px;
  40. overflow: hidden;
  41. text-overflow: ellipsis;
  42. white-space: nowrap;
  43. }
  44. /* 单行文本截断 */
  45.  
  46. .text-ellipsis {
  47. position: relative;
  48. width: 100%;
  49. overflow: hidden;
  50. }
  51. .text-ellipsis .ellipsis-before {
  52. float: left;
  53. width: 5px;
  54. }
  55. .text-ellipsis .ellipsis-after {
  56. font-size: 20px;
  57. text-align: right;
  58. float: right;
  59. position: relative;
  60. width: 50px;
  61. left: 100%;
  62. margin-left: -45px;
  63. padding-right: 5px;
  64. background: linear-gradient(to right, rgba(255, 255, 255, 0), #ffffff 60%);
  65. }
  66.  
  67. .text-ellipsis .ellipsis-content {
  68. float: right;
  69. width: 100%;
  70. margin-left: -5px;
  71. word-break: break-all;
  72. }
  73. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement