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 小时前
element级联选择器:已选中一个二级节点,随后又点击了一个一级节点(仅浏览,未确认选择),此时下拉框失去焦点并关闭
javascript·vue.js·elementui
程序员爱钓鱼13 小时前
Node.js 编程实战:文件读写操作
前端·后端·node.js
PineappleCoder13 小时前
工程化必备!SVG 雪碧图的最佳实践:ID 引用 + 缓存友好,无需手动算坐标
前端·性能优化
JIngJaneIL13 小时前
基于springboot + vue古城景区管理系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot·后端
敲敲了个代码13 小时前
隐式类型转换:哈基米 == 猫 ? true :false
开发语言·前端·javascript·学习·面试·web
澄江静如练_14 小时前
列表渲染(v-for)
前端·javascript·vue.js
JustHappy14 小时前
「chrome extensions🛠️」我写了一个超级简单的浏览器插件Vue开发模板
前端·javascript·github
Loo国昌14 小时前
Vue 3 前端工程化:架构、核心原理与生产实践
前端·vue.js·架构
sg_knight14 小时前
拥抱未来:ECMAScript Modules (ESM) 深度解析
开发语言·前端·javascript·vue·ecmascript·web·esm