当前位置: 首页 > 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.zhongyajixie.com/news/45856.html

相关文章:

  • 网站APP注册做任务营销渠道模式有哪些
  • 我想学习做网站国外免费建站网站搭建
  • 世界杯网站源码下载今日头条关键词工具
  • 渭南网站建设价格网上推广
  • 东莞网站建设效果信息流广告代理商排名
  • dedecms建设慕课网站茶叶营销策划方案
  • php语言 网站建设三只松鼠的软文范例
  • 做农业网站排名优化价格
  • 承建网站百度上如何发广告
  • 做加密网站全站加密的最低成本推手平台哪个靠谱
  • 动态网站用数据库怎么做百度seo网络营销书
  • 招商外包象山关键词seo排名
  • 去掉wordpressseo查询在线
  • 怎样做网站吸引客户市场推广和销售的区别
  • 高端网站建设公司排行竞价排名是什么
  • 现在较为常用的网站开发技术可以免费打开网站的软件
  • 网站建设策划书5000字怎么把抖音关键词做上去
  • dedecms招聘网站优化推荐
  • 怎么做链接网站百度关键词排名批量查询
  • 广州微信网站建设企业百度推广怎么收费
  • 网站怎么增加流量seo网站推广助理招聘
  • 建设学校网站策划书seo81
  • 邯郸做网站服务商免费域名邮箱
  • 网站建设介绍上海网站快速优化排名
  • 做小型网站的公司网站搜索排名优化
  • 惠州网站建设翻译百度高搜
  • 湘西北京网站建设网络营销的类型
  • 做网站售后好的公司信阳搜索引擎优化
  • 网站三级页面国外浏览器搜索引擎入口
  • 买布自己做网站衣服的seo优化在线诊断