1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <template>
- <div class="cus-ellipsis" ref="ref_main">
- <div class="cus-ellipsis-temp" ref="ref_temp">{{value}}</div>
- <el-tooltip
- :disabled="!isEllipsis"
- :content="value"
- placement="top"
- >
- <div class="__text-ellipsis">{{value}}</div>
- </el-tooltip>
- </div>
- </template>
- <script lang="ts">
- import {
- defineComponent,
- computed,
- onMounted,
- ref,
- reactive,
- watch,
- getCurrentInstance,
- ComponentInternalInstance,
- toRefs,
- nextTick
- } from 'vue'
- import {useStore} from 'vuex'
- import {useRouter, useRoute} from 'vue-router'
- export default defineComponent({
- name: 'CusEllipsis',
- components: {},
- props: {
- value: { required: true, type: String }
- },
- setup(props) {
- const store = useStore();
- const router = useRouter();
- const route = useRoute();
- const that = (getCurrentInstance() as ComponentInternalInstance).appContext.config.globalProperties
- const state = reactive({})
- const ref_main = ref()
- const ref_temp = ref()
- const isEllipsis = computed(() => {
- if (props.value) {
- return ref_temp.value?.clientWidth > ref_main.value?.clientWidth
- }
- return false
- })
- return {
- ...toRefs(state),
- isEllipsis,
- ref_main,
- ref_temp
- }
- },
- })
- </script>
- <style scoped lang="scss">
- .cus-ellipsis {
- width: 100%;
- .cus-ellipsis-temp {
- word-break: break-all;
- white-space: nowrap;
- position: absolute;
- visibility: hidden;
- }
- }
- </style>
|