利用Element的Tag标签简单实现类型管理

参考Element官方例子:

Tag标签

对于类型这个标识字段,对应一个单独表,也确实没有多余字段,我不想用form表单,然后直接参考了例子就拿来用了

1、页面引入

        <el-dialog  :visible.sync="newsSetVisible" >
                <el-form :inline="true"  class="demo-form-inline">
                <el-tag
                        :key="tag"
                        v-for="tag in dynamicTags"
                        closable
                        :disable-transitions="false"
                        @close="handleClose(tag)">
                    {{tag}}
                </el-tag>
                <el-input
                        class="input-new-tag"
                        v-if="inputVisible"
                        v-model="inputValue"
                        ref="saveTagInput"
                        size="small"
                        @keyup.enter.native="handleInputConfirm"
                        @blur="handleInputConfirm"
                >
                </el-input>
                <el-button v-else class="button-new-tag" size="small" @click="showInput">+ 新增类型</el-button>
            </el-form>
        </el-dialog>

2、监听相关事件并调用接口

      handleClose(tag){
        this.$confirm("为避免误操作,请确定是否删除?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.axios
            .post("./ttp/server/app/delNewsType?name=" + tag)
            .then(res => {
              if (res.data.status) {
                this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1);
              } else {
                this.$message({
                  type: "error",
                  message: res.data.message
                });
              }
            });
        });
      },

      showInput() {
        this.inputVisible = true;
        this.$nextTick(_ => {
          this.$refs.saveTagInput.$refs.input.focus();
        });
      },
      getNewsType(){
        this.axios
          .post("./ttp/server/app/getNewsTypeList")
          .then(res => {
            this.inputVisible = false;
            this.inputValue = '';
            this.dynamicTags = res.data.data;
          });
      },
      handleInputConfirm() {
        let inputValue = this.inputValue;
        if (inputValue) {
          let i = this.dynamicTags.indexOf(inputValue);
          if (i>-1){
            this.$message({
              type: "error",
              message: "该类型已存在"
            });
            return ;
          }
          this.axios
            .post("./ttp/server/app/addNewsType?name=" + inputValue)
            .then(res => {
              if (res.data.status) {
                this.dynamicTags.push(inputValue);
                this.inputVisible = false;
                this.inputValue = '';
              }else {
                this.$message({
                  type: "error",
                  message: res.data.message
                });
              }
            });

        }else {
          this.$message({
            type: "error",
            message: "新增类型不能为空值"
          });
        }

      },

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

菜鸟茜

随多随少随你心意^-^

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值