誉天在线项目~ElementPlus Tag标签用法

效果图

页面展现

java 复制代码
      <el-form-item label="课程标签">
        <el-tag
            v-for="tag in dynamicTags"
            :key="tag"
            class="mx-1"
            closable
            :disable-transitions="false"
            @close="handleClose(tag)"
            style="margin:5px;"
        >
          {{ tag }}
        </el-tag>
        <el-input
            style="width:200px;"
            v-if="inputVisible"
            ref="InputRef"
            v-model="inputValue"
            class="ml-1 w-20"
            size="small"
            @keyup.enter="handleInputConfirm"
            @blur="handleInputConfirm"
        />
        <el-button v-else class="button-new-tag ml-1" size="small" @click="showInput">
          + 新标签
        </el-button>
      </el-form-item>

初始化

java 复制代码
//tag标签
const inputValue = ref('')
const dynamicTags = ref([])

const inputVisible = ref(false)
const InputRef = ref()

const handleClose = (tag) => {
  dynamicTags.value.splice(dynamicTags.value.indexOf(tag), 1)
}

const showInput = () => {
  inputVisible.value = true
  nextTick(() => {
    InputRef.value.input.focus()
  })
}

const handleInputConfirm = () => {
  if (inputValue.value) {
    dynamicTags.value.push(inputValue.value)
  }
  inputVisible.value = false
  inputValue.value = ''
}

保存时

java 复制代码
//把数组转化成字符串,多个值以逗号隔开
  form.data.tags = dynamicTags.value.join(",")

回显时

java 复制代码
//回显课程标签:数据库存储字符串,页面是数组。
  dynamicTags.value = form.data.tags.split(",")   //将字符串拆成数组
相关推荐
Q一件事23 分钟前
ArcGIS中TypeError: can‘t multiply sequence by non-int of type ‘str‘错误
前端·javascript·arcgis
美狐美颜SDK开放平台1 小时前
从视频处理到实时渲染:直播APP中视频美颜SDK的关键技术解析
前端·人工智能·架构·实时互动·音视频·视频美颜sdk
yume_sibai1 小时前
ES6 核心知识点完全总结(变量 + 箭头函数 + 解构 + Promise + 模块化)
前端·ecmascript·es6
Moment1 小时前
为什么市面上的 coding agent 大多数都基于Nodejs?
前端·后端·面试
吃瓜的猹1 小时前
Gemini 3.8 Flash 是真的站起来了,一起来看看我到底做了什么吧~
前端
光影少年1 小时前
React18 对RN 的影响
android·前端·react.js·ios·前端框架
tryCbest2 小时前
Vue Router学习及使用
前端·vue.js
杉氧2 小时前
丝滑的奥秘:Reanimated 3 动画引擎与手势处理(Gesture Handler)
android·前端·react native
用户970161501682 小时前
浏览器切到后台后,AI 给我的代码就失效了:我拿 3 个模型测了 6 个定时器坑
前端·代码规范
蓝星空20002 小时前
GPT Image 2.5 生图模型已上线,支持 Flare 与 Sunburst 型号选择
前端·gpt·aigc·image2·imagen