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>
相关推荐
共享家95271 天前
搭建 AI 聊天机器人:”我的人生我做主“
前端·javascript·css·python·pycharm·html·状态模式
Halo_tjn1 天前
基于封装的专项 知识点
java·前端·python·算法
有来技术1 天前
Spring Boot 4 + Vue3 企业级多租户 SaaS:从共享 Schema 架构到商业化套餐设计
java·vue.js·spring boot·后端
东东5161 天前
学院个人信息管理系统 (springboot+vue)
vue.js·spring boot·后端·个人开发·毕设
m0_748229991 天前
Vue2 vs Vue3:核心差异全解析
前端·javascript·vue.js
C澒1 天前
前端监控系统的最佳实践
前端·安全·运维开发
xiaoxue..1 天前
React 手写实现的 KeepAlive 组件
前端·javascript·react.js·面试
hhy_smile1 天前
Class in Python
java·前端·python
小邓吖1 天前
自己做了一个工具网站
前端·分布式·后端·中间件·架构·golang
南风知我意9571 天前
【前端面试2】基础面试(杂项)
前端·面试·职场和发展