🐛(component): tooltip

修复文缩小浏览器窗口时文字出现...时鼠标放上去不会显示tooltip问题
This commit is contained in:
dingyongya 2022-06-30 15:48:23 +08:00
parent 57dac27825
commit c49f0c99c3
2 changed files with 21 additions and 6 deletions

View File

@ -10,6 +10,7 @@
import "./index.less"; import "./index.less";
import LayPopper from "../popper/index.vue"; import LayPopper from "../popper/index.vue";
import { defineComponent, ref } from "vue"; import { defineComponent, ref } from "vue";
import { useEventListener } from "@vueuse/core";
export default defineComponent({ export default defineComponent({
name: "LayTooltip", name: "LayTooltip",
components: { components: {
@ -43,7 +44,7 @@ export default defineComponent({
}, },
setup() { setup() {
const isMounted = ref(false); const isMounted = ref(false);
const refTooltip = ref(null); const refTooltip = ref<any>(null);
return { return {
isMounted, isMounted,
refTooltip, refTooltip,
@ -55,11 +56,20 @@ export default defineComponent({
}, },
}, },
mounted() { mounted() {
if (this.isAutoShow) {
useEventListener("resize", () => {
this.setEllipsis();
});
}
this.$nextTick(() => { this.$nextTick(() => {
this.setEllipsis();
});
},
methods: {
setEllipsis() {
if (this.refTooltip) { if (this.refTooltip) {
if ( let tooltipHtml = this.refTooltip;
this.refTooltip.offsetWidth >= this.refTooltip.firstChild.offsetWidth if (tooltipHtml.offsetWidth >= tooltipHtml.firstChild.offsetWidth) {
) {
this.isMounted = false; this.isMounted = false;
} else { } else {
this.isMounted = true; this.isMounted = true;
@ -67,7 +77,7 @@ export default defineComponent({
} else { } else {
this.isMounted = true; this.isMounted = true;
} }
}); },
}, },
}); });
</script> </script>

View File

@ -7,7 +7,12 @@
::: demo ::: demo
<template> <template>
<div style="width: 125px; "> <div style="max-width: 100%; ">
<lay-tooltip content="假装这里有文字提示假装这里有文字提示假装这里有文字提示假装这里有文字提示" ref="tooltip" :isAutoShow="true">
假装这里有文字提示假装这里有文字提示假装这里有文字提示假装这里有文字提示
</lay-tooltip>
</div>
<div style="max-width: 129px; margin-top: 20px">
<lay-tooltip content="假装这里有文字提示" ref="tooltip" :isAutoShow="true"> <lay-tooltip content="假装这里有文字提示" ref="tooltip" :isAutoShow="true">
假装这里有文字提示 假装这里有文字提示
</lay-tooltip> </lay-tooltip>