其他分享
首页 > 其他分享> > tag标签

tag标签

作者:互联网

<el-tag
  :key="ietm"
  v-for="itemin dynamicTags"
  closable
  :disable-transitions="false"
  >
  {{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">+ New Tag</el-button>
<script>
  export default {
    data() {
      return {
        dynamicTags: [],
        inputVisible: false,
        inputValue: ''
      };
    },
    methods: {
      showInput() {
        this.inputVisible = true;
        this.$nextTick(_ => {
          this.$refs.saveTagInput.$refs.input.focus();
        });
      },

      handleInputConfirm() {
        let inputValue = this.inputValue;
        if (inputValue) {
          this.dynamicTags.push(inputValue);
        }
        this.inputVisible = false;
        this.inputValue = '';
      }
    }
  }
</script>
<style>
  .input-new-tag {
    width: 90px;
 
  }
</style>

标签:false,标签,refs,dynamicTags,tag,inputValue,inputVisible
来源: https://blog.csdn.net/weixin_46852620/article/details/113690773