elementplus组件文本框设置前缀

elementplus的文本框组件不支持设置前缀

作为一个合格的切图仔,只能另辟蹊径了

用的 绝对定位 + 缩进 达到效果

效果:

代码:

html 复制代码
<template>
  <div class="textarea textarea-prefix">
    <span ref="prefixRef" class="prefix">前缀</span>
    <el-input v-model="title" type="textarea" :rows="2" lengthType="characterPunc" useMaxlengthError />
  </div>
</template>

<script setup lang="ts">
import { nextTick, onMounted, ref } from 'vue';

const prefixRef = ref(null);
const prefixWidth = ref('');

const title = ref('内容');

onMounted(() => {
  nextTick(() => {
    prefixWidth.value = `${prefixRef.value?.offsetWidth || 0}px`;
  });
});
</script>

<style lang="scss" scoped>
.textarea {
  &.textarea-prefix {
    position: relative;
    .prefix {
      position: absolute;
      z-index: 1;
      height: 20px;
      line-height: 20px;
      padding: 0 5px;
      margin: 5px;
      color: #555;
      min-width: 20px;
      border-radius: 2px;
      background: #eef1f6;
    }
    :deep() {
      .el-textarea__inner {
        text-indent: v-bind('prefixWidth');
      }
    }
  }
}
</style>
相关推荐
正在学习前端的---小方同学2 小时前
vue-easy-tree树状结构
前端·javascript·vue.js
毕业设计制作和分享3 小时前
springboot150基于springboot的贸易行业crm系统
java·vue.js·spring boot·后端·毕业设计·mybatis
键盘不能没有CV键5 小时前
【图片处理】✈️HTML转图片字体异常处理
前端·javascript·html
yantuguiguziPGJ6 小时前
WPF 联合 Web 开发调试流程梳理(基于 Microsoft.Web.WebView2)
前端·microsoft·wpf
大飞记Python6 小时前
部门管理|“编辑部门”功能实现(Django5零基础Web平台)
前端·数据库·python·django
tsumikistep7 小时前
【前端】前端运行环境的结构
前端
你的人类朋友7 小时前
【Node】认识multer库
前端·javascript·后端
Aitter7 小时前
PDF和Word文件转换为Markdown的技术实现
前端·ai编程
mapbar_front8 小时前
面试问题—上家公司的离职原因
前端·面试
昔人'9 小时前
css使用 :where() 来简化大型 CSS 选择器列表
前端·css