当前位置: 首页 > news >正文

郑州企业网站开发长沙市最新疫情

郑州企业网站开发,长沙市最新疫情,国外的创意设计网站,怎么做不花钱的网站代码见文末 vue3实现 最开始就用的vue3实现,如下 Vue3实现方式 vue2开发和使用文档 组件功能 TooltipText 是一个文字展示组件,具有以下功能: 文本显示:支持单行和多行文本显示。自动判断溢出:判断文本是否溢出…

代码见文末

vue3实现

最开始就用的vue3实现,如下

Vue3实现方式

vue2开发和使用文档

组件功能

TooltipText 是一个文字展示组件,具有以下功能:

  • 文本显示:支持单行和多行文本显示。
  • 自动判断溢出:判断文本是否溢出,根据溢出情况显示 tooltip。
  • 自定义样式:可以通过 props 修改文本样式和 Tooltip 样式。
  • 行数限制:支持多行文本显示,超出部分通过行数限制显示省略号。

使用方法
  1. 引入组件TooltipText 注册到你的 Vue 项目中:

    import TooltipText from './TooltipText.vue';export default {components: {TooltipText,},
    };
    
  2. 组件模板示例

    <template><TooltipText:content="'这是一个演示文本。'":lineClamp="2":maxWidth="300":tooltipOptions="{placement: 'top',effect: 'light',trigger: 'hover',}":outStyle="{ color: '#333', fontSize: '16px' }"/>
    </template>
    
  3. 传入参数

    属性名类型默认值说明
    tooltipOptionsObject{ content: 'Bottom center', placement: 'bottom', effect: 'dark', trigger: 'hover' }Tooltip 的配置选项,参考 Element UI 的配置。
    outStyleObject{ fontSize: '14px' }外部样式对象,用于自定义文字样式。
    contentString''显示的文本内容。
    lineClampNumber1显示的行数限制,超出部分会显示省略号。
    maxWidthNumber0Tooltip 的最大宽度(单位 px)。
  4. 样式自定义 可通过 tooltipOptionsoutStyle 自定义 Tooltip 和文字样式:

    :tooltipOptions="{effect: 'light',placement: 'right',trigger: 'hover',
    }"
    :outStyle="{ fontSize: '18px', color: '#555' }"
    
  5. 动态内容 内容变动后会自动检查溢出并更新 Tooltip 显示状态,无需额外操作。


开发细节
  1. 溢出检查

    • 单行文本通过 scrollWidthclientWidth 比较实现。
    • 多行文本通过 scrollHeightclientHeight 比较实现。
  2. 计算属性

    • computedMaxPopWidth 动态计算 Tooltip 的最大宽度,默认为文字容器宽度的 50%。
    • computedIfWrap 判断是否为多行文本,根据 lineClamp 属性动态更新。
  3. 监听与更新

    • 使用 watch 监听 content 的变动,在内容更新后重新计算溢出状态。
  4. 样式

    • text-auto-nowrap:单行文本样式,自动截断显示省略号。
    • text-auto-wrap:多行文本样式,支持行数限制。

注意事项
  • 如果文本内容较长但设置了过小的 maxWidth,可能导致 Tooltip 内容显示不全。
  • 若需要动态调整文本或 Tooltip 样式,请确保 props 数据及时更新。

通过此组件可以轻松实现文本展示与溢出提示的功能,并满足多样化的样式需求。

<template><!-- Tooltip and text display container --><div><!-- Tooltip element from Element UI --><el-tooltipv-bind="tooltipOptions" <!-- Bind tooltip options -->:popper-class="!toolTipShow ? 'hide-tooltip tooltip-popper' : 'tooltip-popper'" <!-- Conditionally apply tooltip classes -->><!-- Tooltip content slot --><template #content><div class="tooltip-content" :style="{ maxWidth: maxWidth || computedMaxPopWidth + 'px' }" <!-- Set maximum width for tooltip content -->>{{ content }} <!-- Display tooltip content --></div></template><!-- Text display with optional line clamp and styles --><div:class="{ 'text-auto-wrap': computedIfWrap, 'text-auto-nowrap': !computedIfWrap }" <!-- Apply wrapping styles based on computed value -->ref="textAutoRef" <!-- Reference for DOM access -->:style="{'-webkit-line-clamp': lineClamp, <!-- Apply line clamp for text -->'line-clamp': lineClamp, <!-- Apply line clamp for text -->...outStyle <!-- Merge additional styles -->}">{{ content }} <!-- Display main text content --></div></el-tooltip></div>
</template><script>
export default {name: 'TooltipText',props: {// Tooltip options passed to Element UI el-tooltiptooltipOptions: {type: Object,default: () => ({content: 'Bottom center',placement: 'bottom',effect: 'dark',trigger: 'hover',}),},// Additional styles for the text containeroutStyle: {type: Object,default: () => ({fontSize: '14px',}),},// Text content to displaycontent: {type: String,default: '',},// Number of lines to clamp text tolineClamp: {type: Number,default: 1,},// Maximum width for tooltip contentmaxWidth: {type: Number,default: 0,},},data() {return {toolTipShow: false, // Whether to show the tooltiptextAutoRef: null, // Reference to the text container element};},computed: {// Compute the maximum width for the tooltip dynamicallycomputedMaxPopWidth() {if (this.$refs.textAutoRef) {return this.$refs.textAutoRef.clientWidth * 0.5; // Tooltip width is half of the text container width}return '100%'; // Default to full width if reference is not available},// Determine if text wrapping should be applied based on lineClampcomputedIfWrap() {return this.lineClamp > 1;},},watch: {// Watch for changes in content and re-check overflowcontent: {handler() {this.$nextTick(() => {this.checkOverflow();});},immediate: true,},},methods: {// Check if the text content overflows its containercheckOverflow() {if (!this.$refs.textAutoRef) return;if (!this.computedIfWrap) {// Single-line text overflow checkthis.toolTipShow = this.$refs.textAutoRef.scrollWidth > this.$refs.textAutoRef.clientWidth;} else {// Multi-line text overflow checkthis.toolTipShow = this.$refs.textAutoRef.scrollHeight > this.$refs.textAutoRef.clientHeight;}},},mounted() {// Perform overflow check after component is mountedthis.$nextTick(this.checkOverflow);},
};
</script><style lang="scss" scoped>.text-auto-nowrap {width: 100%;white-space: nowrap; <!-- Prevent text wrapping -->overflow: hidden; <!-- Hide overflowing text -->text-overflow: ellipsis; <!-- Show ellipsis for overflow -->text-align: left; <!-- Align text to the left -->}.text-auto-wrap {width: 100%;text-align: left; <!-- Align text to the left -->overflow: hidden; <!-- Hide overflowing text -->text-overflow: ellipsis; <!-- Show ellipsis for overflow -->display: -webkit-box; <!-- Use a flex container for wrapping -->-webkit-box-orient: vertical; <!-- Set vertical orientation for line clamp -->}
</style><style>.hide-tooltip {visibility: hidden !important; <!-- Hide the tooltip completely -->}
</style>

http://www.hkea.cn/news/841544/

相关文章:

  • dw做网站的流程客户引流的最快方法是什么
  • 做网站app优惠活动的交换链接营销成功案例
  • 企业公示信息查询系统山西上海百度推广优化公司
  • 上海网站排名优化价格武汉百度快照优化排名
  • 做网站小程序如何做广告宣传与推广
  • 网站建设背景朝阳百度新闻网页
  • 专门做拼团的网站西安网站开发
  • 怎么看网站开发语言太原seo推广
  • 什么网站做宣传好新乡网站seo
  • 济南网站制作服务价格信息流优化师前景
  • 新手制作网站工具bt磁力猪
  • 怎么做网站系统深圳头条新闻
  • 北京网站设计公司新鸿儒seo公司的选上海百首网络
  • 百姓网二手拖拉机百度seo优化排名客服电话
  • 北京南站是丰台站吗seo优化什么意思
  • 外贸营销型建站关键词全网搜索工具
  • 有什么网站可以做扣扣头像腾讯企点app下载安装
  • 网站设计怎么做链接拉新推广怎么快速拉人
  • 怎么自己做礼品网站补肾壮阳吃什么药效果好
  • 网站用户建设的设计与实现网站推广营销运营方式
  • html5韩国网站模板seo网站优化培训班
  • 网站被iframe信息推广的方式有哪些
  • 通信技术公司网站建设app推广代理
  • 做电影网站会违法吗营销说白了就是干什么的
  • 用外链技术做视频网站关键词在线听免费
  • 做网站常用的css最近三天的新闻热点
  • 全国人大常委会副委员长登封seo公司
  • 顶岗实践网站开发推广管理
  • 九号公司网站优化效果
  • 模板网站建设方案北京seo排名收费