当前位置: 首页 > news >正文

el-input输入框需要支持多输入,最后传输给后台的字段值以逗号分割

需求:一个输入框字段需要支持多次输入,最后传输给后台的字段值以逗号分割
解决方案:结合了el-tag组件的动态编辑标签 那块的代码

//子组件
<template><div class="input-multiple-box" id='inputMultipleBox'><div><el-tag v-for="(tag, index) in inputTagList" :key="index" type="info" closable @close="handleClose(index)">{{ tag }}</el-tag></div><el-inputv-model="inputValue"@keyup.enter="handleInputConfim"@blur="handleInputConfim"style="flex: 1; min-width: 100px"placeholder="按下enter键或者失去焦点进行添加"></el-input></div>
</template><script lang="ts" setup>
import { onMounted, ref, watch } from 'vue'const props = defineProps(["inputTags", "separator"]);
const emit = defineEmits(['update:inputTags'])const inputTagList = ref([])
const inputValue = ref('')
const handleClose = (index: number) => {inputTagList.value.splice(index, 1)emit('update:inputTags', inputTagList.value.join(props.separator || ','))
}
const handleInputConfim = () => {if (inputValue.value) {inputTagList.value.push(inputValue.value)inputValue.value = ''emit('update:inputTags', inputTagList.value.join(props.separator || ','))}
}watch(()=>props.inputTags, (val, pre) => {inputTagList.value = props.inputTags.split(props.separator || ',')
});onMounted(() => {if (props.inputTags) {inputTagList.value = props.inputTags.split(props.separator || ',')}
})
</script><style lang="scss" scoped>
.input-multiple-box {width: 100%;border-radius: 4px;border: 1px solid #dcdfe6;// padding: 0 5px;display: flex;flex-wrap: wrap;
}
</style>
<style lang="scss">
#inputMultipleBox {.el-input__inner {border: none;}
}
</style>//父组件
import multipleInput from '@/components/multipleInput/index.vue'
<multipleInputv-model:inputTags="form.modbus"placeholder="请输入"clearable></multipleInput>

实现效果图
在这里插入图片描述

http://www.lryc.cn/news/516204.html

相关文章:

  • C# 枚举格式字符串
  • 【51单片机-零基础chapter1】
  • 记录:导出功能:接收文件流数据进行导出(vue3)
  • 基于Spring Boot + Vue3实现的在线汽车保养维修预约管理系统源码+文档
  • PHP框架+gatewayworker实现在线1对1聊天--接收消息(7)
  • 18.1、网络安全策略分类 流程 内容
  • 深入理解连接池:从数据库到HTTP的优化之道
  • 【2025最新计算机毕业设计】基于SpringBoot+Vue智慧养老医护系统(高质量源码,提供文档,免费部署到本地)【提供源码+答辩PPT+文档+项目部署】
  • 关于使用vue-cropperjs上传一张图后,再次上传时,裁剪的图片不更新的问题
  • 学习threejs,导入VTK格式的模型
  • 大麦抢票科技狠活
  • PostgreSQL 表达式
  • WPF区域导航+导航参数使用+路由守卫+导航日志
  • Springboot启动报错:Failed to start bean ‘documentationPluginsBootstrapper‘
  • qt-C++笔记之动画框架(Qt Animation Framework)入门
  • C++26 函数契约(Contract)概览
  • Flink CDC 自定义函数处理 SQLServer XML类型数据 映射 doris json字段方案
  • F.interpolate函数
  • 华为交换机---自动备份配置到指定ftp/sftp服务器
  • nginx学习之路-nginx配置https服务器
  • UCAS 24秋网络认证技术 CH10 SSL 复习
  • 【linux内核分析-存储】EXT4源码分析之“文件删除”原理【七万字超长合并版】(源码+关键细节分析)
  • 代码随想录 day62 第十一章 图论part11
  • springboot571基于协同过滤算法的私人诊所管理系统(论文+源码)_kaic
  • Uniapp Android 本地离线打包(详细流程)
  • vite+vue3动态引入资源文件(问题已解决但离了个大谱)
  • 通过 4 种方式快速将音乐从 iPod 传输到 Android
  • ArcGIS中怎么把数据提取到指定范围(裁剪、掩膜提取)
  • 【Vaadin flow 实战】第3讲-快速上手构建VaadinFlow+Springboot的全栈web项目
  • HBase Cassandra的部署和操作