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>
相关推荐
IMPYLH31 分钟前
HTML 的 <data> 元素
前端·html
YHHLAI1 小时前
[特殊字符] 面试中的 Promise —— 从入门到精通
前端·javascript·面试
leoZ2312 小时前
Claude 驱动的全栈开发:Spring Boot + Vue 的 BS 架构实践
vue.js·spring boot·架构
kyriewen3 小时前
我扒了 GPT-5.6 的全部编程跑分——有一项 OpenAI 没敢放出来
前端·gpt·ai编程
前端H3 小时前
微前端 v3 架构升级:从加载隔离到状态协同
前端·架构·状态模式
陆枫Larry5 小时前
小程序包体积优化:用 SVG 图片替换 iconfont,并保留 CSS 控色能力
前端
环境栈笔记6 小时前
多账号浏览器选型检查清单:Profile、权限、Session 和任务日志怎么评估
前端·人工智能·后端·自动化
前端炒粉6 小时前
手写promise
java·前端·javascript
LaughingZhu6 小时前
智能体经典范式构建:ReAct、Plan-and-Solve 与 Reflection
前端·react.js·前端框架
荒诞英雄6 小时前
从 17MB Vendor 大包到按需加载:Vite 多入口 Vue 组件库首屏优化实践
vue.js·vite