elementui select中添加新增标签

javascript 复制代码
 <el-select v-model="ruleForm.eventType" :placeholder="`请选择事件类型,可手动添加`" ref="template" clearable @visible-change="(v) => visibleChange(v, 'template')">
                <el-option v-for="item in eventTypeOptions" :key="item.value" :label="item.label" :value="item.value">
                  {{ item.label }}
                  <div class="flag" @click="showShipTemplate(item.code, true)"></div>
                </el-option>
              </el-select>
javascript 复制代码
 ruleForm: {
        eventType: "",
      },
 eventTypeOptions: [
        {
          value: "1",
          label: "水污染",
        },
        {
          value: "2",
          label: "水污染1",
        },
      ],
javascript 复制代码
    showShipTemplate() {
      this.$prompt(`请输入新的类型`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        inputValidator: (value) => {
          //非空验证
          if (!value) {
            return "请输入内容";
          }
        },
      })
        .then(({ value }) => {
          this.ruleForm.eventType = value;
          this.eventTypeOptions.push({
            value: value,
            label: value,
          });
          console.log("确定");
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消输入",
          });
        });
    },
    visibleChange(visible, refName) {
      this.$nextTick(() => {
        if (visible) {
          const ref = this.$refs[refName];
          let popper = ref.$refs.popper;
          if (popper.$el) popper = popper.$el;
          if (
            !Array.from(popper.children).some(
              (v) => v.className === "el-template-menu__list"
            )
          ) {
            const el = document.createElement("ul");
            el.className = "el-template-menu__list";
            el.style =
              "border-bottom:2px solid rgb(219 225 241); padding:0; color:rgb(64 158 255);font-size: 13px;margin: 0px;text-align: center; ";
            el.innerHTML = `<li class="el-cascader-node text-center" style="height:36px;line-height: 36px;">
            <span class="el-cascader-node__label"><i class="font-blue el-icon-plus"></i>新增类型</span>
            </li>`;
            // console.log(popper.childNode,'sssssssssssssss')
            // console.log(popper.children[0], "231111111111");
            // console.log(popper, "popper");
            if (this.isUp) {
              popper.insertBefore(el, popper.children[0]);
            } else {
              popper.appendChild(el);
            }
            el.onclick = () => {
              this.showShipTemplate(null, false);
            };
          }
        }
      });
    },
相关推荐
CHQIUU6 分钟前
如何在PDF.js中改造viewer.html以实现PDF的动态加载
javascript·pdf·html
拉不动的猪29 分钟前
简单回顾下useMemo
前端·javascript·面试
烛阴1 小时前
JavaScript 求幂运算符:告别 Math.pow(),拥抱更优雅的次方计算!
前端·javascript
染的人1 小时前
Layui Table组件,设置data数据源,以及page为False,表格只能显示10条数据的问题
前端·layui
玖玖passion1 小时前
js中的栈
前端·算法
只会安静敲代码的 小周2 小时前
【长按图片识别】uniapp vue开发时,点击图片识别—实现转发、收藏、识别图片二维码
前端·vue.js·uni-app
F26017755922 小时前
uniapp中uni-easyinput 使用@input 不改变绑定的值
java·前端·uni-app
shmily ....2 小时前
从零构建 Vue3 登录页:结合 Vant 组件与 Axios 实现完整登录功能
前端·javascript·vue.js
汐汐咯2 小时前
HTML+CSS+JS(1)
javascript·css·html
Hello.Reader3 小时前
给你的 Rust 通用库“插上” WebAssembly 的翅膀
javascript·rust·wasm