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>
相关推荐
万少13 小时前
HarmonyOS 开发必会 5 种 Builder 详解
前端·harmonyos
橙序员小站15 小时前
Agent Skill 是什么?一文讲透 Agent Skill 的设计与实现
前端·后端
炫饭第一名17 小时前
速通Canvas指北🦮——基础入门篇
前端·javascript·程序员
王晓枫18 小时前
flutter接入三方库运行报错:Error running pod install
前端·flutter
符方昊18 小时前
React 19 对比 React 16 新特性解析
前端·react.js
ssshooter18 小时前
又被 Safari 差异坑了:textContent 拿到的值居然没换行?
前端
曲折18 小时前
Cesium-气象要素PNG色斑图叠加
前端·cesium
Forever7_18 小时前
Electron 淘汰!新的桌面端框架 更强大、更轻量化
前端·vue.js
不会敲代码118 小时前
前端组件化样式隔离实战:React CSS Modules、styled-components 与 Vue scoped 对比
css·vue.js·react.js
Angelial18 小时前
Vue3 嵌套路由 KeepAlive:动态缓存与反向配置方案
前端·vue.js