CusEllipsis.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <template>
  2. <div class="cus-ellipsis" ref="ref_main">
  3. <div class="cus-ellipsis-temp" ref="ref_temp">{{value}}</div>
  4. <el-tooltip
  5. :disabled="!isEllipsis"
  6. :content="value"
  7. placement="top"
  8. >
  9. <div class="__text-ellipsis">{{value}}</div>
  10. </el-tooltip>
  11. </div>
  12. </template>
  13. <script lang="ts">
  14. import {
  15. defineComponent,
  16. computed,
  17. onMounted,
  18. ref,
  19. reactive,
  20. watch,
  21. getCurrentInstance,
  22. ComponentInternalInstance,
  23. toRefs,
  24. nextTick
  25. } from 'vue'
  26. import {useStore} from 'vuex'
  27. import {useRouter, useRoute} from 'vue-router'
  28. export default defineComponent({
  29. name: 'CusEllipsis',
  30. components: {},
  31. props: {
  32. value: { required: true, type: String }
  33. },
  34. setup(props) {
  35. const store = useStore();
  36. const router = useRouter();
  37. const route = useRoute();
  38. const that = (getCurrentInstance() as ComponentInternalInstance).appContext.config.globalProperties
  39. const state = reactive({})
  40. const ref_main = ref()
  41. const ref_temp = ref()
  42. const isEllipsis = computed(() => {
  43. if (props.value) {
  44. return ref_temp.value?.clientWidth > ref_main.value?.clientWidth
  45. }
  46. return false
  47. })
  48. return {
  49. ...toRefs(state),
  50. isEllipsis,
  51. ref_main,
  52. ref_temp
  53. }
  54. },
  55. })
  56. </script>
  57. <style scoped lang="scss">
  58. .cus-ellipsis {
  59. width: 100%;
  60. .cus-ellipsis-temp {
  61. word-break: break-all;
  62. white-space: nowrap;
  63. position: absolute;
  64. visibility: hidden;
  65. }
  66. }
  67. </style>