vue3 element plus el-tooltip文字提示实现多行展示

需求

上传文件时可以提示需要的目录结构

例如需要的提示信息:
─ src.zip                       # 源代码
	─ api.conf                  # 所有请求
	─ assets                 	# 主题 字体等静态资源
	─ components             	# 全局公用组件
	─ directive              	# 全局指令
	─ filters                	# 全局 filter
	─ icons                  	# 项目所有 svg icons
获取组件

Element tooltip

<template>
  <el-tooltip placement="top">
  <template #content>
    多行信息<br/>第二行信息
  </template>
  <el-button>Top center</el-button>
</el-tooltip>
</template>

效果
展示效果

虽然这样可以实现多行展示,但是需要将内容写死在html页面,修改一下,传入变量

<template>
  <div>
    <el-tooltip placement="top">
      <template #content> {{ tip }} </template>
      <el-button>Top center</el-button>
    </el-tooltip>
  </div>
</template>
<script>
export default {
  data() {
    return {
      tip: [
        "提示信息:",
        "─ src.zip                  # 源代码",
        "	─ api.conf                # 所有请求",
        "	─ assets                 	# 主题 字体等静态资源",
        "	─ components             	# 全局公用组件",
        "	─ directive              	# 全局指令",
        "	─ filters                	# 全局 filter",
        "	─ icons                  	# 项目所有 svg icons",
      ],
    };
  },
};
</script>

单纯的引用变量只会在一行展示,继续修改
在这里插入图片描述

<template>
  <div>
    <el-tooltip placement="top">
	  <template #content>
        <template v-for="item in tip" :key="item"> {{ item }}<br /> </template>
      </template>
      <el-button>Top center</el-button>
    </el-tooltip>
  </div>
</template>
<script>
export default {
  data() {
    return {
      tip: [
        "提示信息:",
        "─ src.zip                  # 源代码",
        "	─ api.conf                # 所有请求",
        "	─ assets                 	# 主题 字体等静态资源",
        "	─ components             	# 全局公用组件",
        "	─ directive              	# 全局指令",
        "	─ filters                	# 全局 filter",
        "	─ icons                  	# 项目所有 svg icons",
      ],
    };
  },
};
</script>

可以显示多行了,但是无法体现目录结构
在这里插入图片描述

<template>
  <div>
    <el-tooltip placement="top">
      <template #content>
        <template v-for="item in tips" :key="item">
          {{ item.replace(/\t/g, "&#12288").replace(/\0/g,"&#160") }}<br />
        </template>
      </template>

      <el-button>Top center</el-button>
    </el-tooltip>
  </div>
</template>
<script>
export default {
  data() {
    return {
      tip: [
        "提示信息:",
        "─ src.zip\t\t\t\t         # 源代码",
        "\t\t─ api.conf\t\t\t\t                # 所有请求",
        "\t\t─ assets\t\t\t\t               	# 主题 字体等静态资源",
        "\t\t─ components\t\t\t\t            	# 全局公用组件",
        "\t\t─ directive\t\t\t\t            	# 全局指令",
        "\t\t─ filters\t\t\t              	# 全局 filter",
        "\t\t─ icons\t\t\t\t                	# 项目所有 svg icons",
      ],
    };
  },
};
</script>

添加特殊字符,使用字符串替换,将特殊字符转换为空格,就可以按需求实现想要的布局
在这里插入图片描述

  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值