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

vue3中标签form插件

想写一个系统,对八字进行标注,比如格局,有些八字就有很多格局,于是就想着使用el-tag但是,form表单中如何处理呢?
1
这个时候,就需要自己写一个,modelValue是表单的默认属性

<template><div><el-tag v-for="(item,index) in keywordTags" :key="index" closable @close="handleClose(tag)"size="small" class="mx-1">{{item}}</el-tag><el-input v-if="inputVisible" ref="InputRef" v-model="inputValue" class="ml-1 w-20" size="small" @keyup.enter="handleInputConfirm" @blur="handleInputConfirm"></el-input><el-button v-else class="button-new-tag ml-1" size="small" @click="showInput">+ 新增</el-button></div>
</template>
<script lang="ts" setup>
const inputVisible = ref(false)
import { nextTick,ref,watch,getCurrentInstance } from 'vue'
import type { FormInstance, FormRules,ElInput  } from 'element-plus'
const { proxy }: any = getCurrentInstance();
const emits = defineEmits(['update:modelValue'])
const props = defineProps<{modelValue:String,}>()
const keywordTags = ref([])
const inputValue = ref('')
const InputRef = ref<InstanceType<typeof ElInput>>()
const showInput  = () =>{inputVisible.value = truenextTick(() => {InputRef.value!.input!.focus()})
}
const handleClose = (tag:String) => {keywordTags.value.splice(keywordTags.value.indexOf(tag),1)
}
const handleInputConfirm = () => {if (inputValue.value) {keywordTags.value.push(inputValue.value)}inputVisible.value = falseinputValue.value = ''
}   
watch(()=>keywordTags,(newVal,oldVal)=>{if (!proxy.$_.isEmpty(newVal.value)){console.log(newVal.value.join(','))emits('update:modelValue',newVal.value.join(','))}
},{immediate:true,deep:true})
watch(()=>props.modelValue,(newVal,oldVal)=>{if (!proxy.$_.isEmpty(newVal)){keywordTags.value = newVal.split(',')}
},{immediate:true,deep:true})
</script>
<style lang="less" scoped>
.w-20{width: 50px;
}
.mx-1{margin-right: 10px;
}
</style>
</style>

使用的话参见,这样保存和编辑就很容易了。

<el-form-item label="标签" prop="tags"><udf-tags v-model="form.tags"></udf-tags>
</el-form-item>
http://www.lryc.cn/news/273730.html

相关文章:

  • 企业数字化转型:1个核心、2种力量、3个关键点、4大转型、5大平台
  • Agilent安捷伦E4990A阻抗分析仪20Hz
  • 性能优化-OpenMP概述(一)-宏观全面理解OpenMP
  • Prometheus实战篇:Prometheus监控nginx
  • JVM加载class文件的原理机制
  • 如何使用CapSolver解决Web爬虫中遇到的CAPTCHA问题
  • 杰发科技AC7801——IO模拟IIC注意事项
  • 展台搭建与设计都有哪些思路
  • 解决mock单元测试中 无法获取实体类xxx对应的表名
  • arm64虚拟化技术与kvm实现原理分享
  • 选择 省市区 组件数据 基于vue3 + elment-plus
  • 了解 nextTick
  • C++精进之路(十六)string类和标准模板库
  • 【23.12.29期--Redis缓存篇】谈一谈Redis的集群模式
  • 【算法挨揍日记】day34——647. 回文子串、5. 最长回文子串
  • 欧科云链研究院:奔赴2024,Web3与AI共振引爆数字时代潘多拉魔盒
  • 【Py/Java/C++三种语言OD2023C卷真题】20天拿下华为OD笔试之【数学】2023C-素数之积【欧弟算法】全网注释最详细分类最全的华为OD真题题解
  • uniapp路由
  • 湖南大学-数据库系统-2023期末考试【原题】
  • 【Java EE初阶九】多线程案例(线程池)
  • 理解 Node.js 中的事件循环
  • Mac 软件出现「意外退出」及「打不开」解决方法
  • 随机森林 3(代码)
  • 勒索事件急剧增长,亚信安全发布《勒索家族和勒索事件监控报告》
  • LeetCode1523. Count Odd Numbers in an Interval Range
  • E中国铜金属行业需求前景及未来发展机遇分析报告2024-2030年
  • python SVM 保存和加载模型参数
  • JAVA进化史: JDK12特性及说明
  • Databend 的算力可扩展性
  • 「解析」Windows 如何优雅使用 Terminal