当前位置:网站首页>el-input输入框需要支持多输入
el-input输入框需要支持多输入
2022-07-19 07:02:00 【生活的打工仔】
需求:一个输入框字段需要支持多次输入,最后传输给后台的字段值以逗号分割
实现效果图:
解决方案:参考了el-tags的 #动态编辑标签 那块的代码,只是做了个样式优化
<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-input
v-model="inputValue"
@keyup.enter="handleInputConfim"
@blur="handleInputConfim"
style="flex: 1; min-width: 100px"
placeholder="按下enter键或者失去焦点添加元素"
></el-input>
</div>
</template>
<script lang="ts">
import { defineComponent, onMounted, ref } from 'vue'
export default defineComponent({
props: ['inputTags', 'separator'],
emits: ['update:inputTags'],
setup(props, _) {
const inputTagList = ref<any>([])
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 || ','))
}
}
onMounted(() => {
if (props.inputTags) {
inputTagList.value = props.inputTags.split(props.separator || ',')
}
})
return { inputTagList, inputValue, handleClose, handleInputConfim }
}
})
</script>
<style lang="stylus" scoped>
.input-multiple-box
width: 100%
border-radius: 4px
border: 1px solid #dcdfe6
padding: 0 5px
display: flex
flex-wrap: wrap
</style>
<style lang="stylus">
#inputMultipleBox
.el-input__inner
border: none
</style>
边栏推荐
- Apache impala 4.1 overview
- Will it be optimized if you add a condition to sort by half insertion?
- Wechat applet realizes watch monitoring manually
- Can dynamic table names be implemented in Presto SQL queries?
- About the service life and working principle of fan slip ring
- Chapter 3 business function development (delete the remarks of market activities)
- One question per day on July 17, 2022 (structure + mathematics + greed + pointer)
- In May, 2022, video user insight: user use time increased, and the platform achieved initial results in cost reduction and efficiency increase
- 生产中影响滑环质量的因素
- 215 "double first-class" candidates took the postgraduate entrance examination and were admitted by this "double non University"!
猜你喜欢
随机推荐
导电滑环的内部结构和使用范围
对象的比较
2022 Shandong Province safety officer C certificate operation certificate examination questions and answers
旋转数组 189, 153, 154, 33, 81, 10.03
Wechat applet bindinput and click the button to assign the content of the current text
2022p cylinder filling examination question bank and answers
Bases de données
数字信号处理实验二 IIR数字滤波器设计及软件实现
实现OCR语言识别Demo(一)- BottomSheet实现
crontab无法执行脚本原因及解决方法
第3章业务功能开发(删除市场活动备注)
JS timer and swiper plug-in
Oracle trigger SQL error
Pikachu shooting range SQL injection character injection (get) clearance steps
(图解)FPN的来龙去脉
Rsync了解
优化yum源之优化base库
导电滑环的运行温度
Cake cutting problem [Olympiad Mathematics in grade two of primary school]
Supervisor使用了解