index.vue 920 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <template>
  2. <el-tooltip :content="content" :placement="placement" :disabled="!showTooltip">
  3. <span class="yh-tooltip-content overflow-ellipsis" @mouseenter.stop.prevent="onMouseenter" @mouseleave.stop.prevent="showTooltip = false">{{ content }}</span>
  4. </el-tooltip>
  5. </template>
  6. <script>
  7. export default {
  8. props: {
  9. placement: { type: String, default: "bottom" },
  10. content: { type: String, default: "" },
  11. spacing: { type: Number, default: 0 }
  12. },
  13. data() {
  14. return {
  15. showTooltip: false
  16. }
  17. },
  18. methods: {
  19. onMouseenter({ currentTarget }) {
  20. this.showTooltip = currentTarget.scrollWidth >= currentTarget.parentElement.offsetWidth - this.spacing
  21. }
  22. }
  23. }
  24. </script>
  25. <style lang="scss" scoped>
  26. .yh-tooltip-content {
  27. max-width: 100% !important;
  28. display: inline-block;
  29. }
  30. .overflow-ellipsis {
  31. overflow: hidden;
  32. white-space: nowrap;
  33. text-overflow: ellipsis;
  34. }
  35. </style>