<template>
<div class="app-container">
<div v-for="(tags, tagsIndex) in tagArray" :key="tagsIndex">
<el-tag :key="tag" v-for="tag in dynamicTags[`tag${tagsIndex}`]" closable :disable-transitions="false" @close="handleClose(tag, tagsIndex)">
{{tag}}
</el-tag>
<el-input class="input-new-tag" v-if="inputVisible && currentIndex === tagsIndex" v-model="inputValue" :ref="`saveTagInput${tagsIndex}`" size="small" @keyup.enter.native="handleInputConfirm(tagsIndex)" @blur="handleInputConfirm(tagsIndex)"></el-input>
<el-button v-else class="button-new-tag" size="small" @click="showInput(tagsIndex)">+ New Tag {{tagsIndex}}</el-button>
<br />
<br />
</div>
</div>
</template>
<script>
export default {
data() {
return {
tagArray: [...Array(3).keys()],
dynamicTags: {
'tag0': [],
'tag1': [],
'tag2': []
},
inputVisible: false,
currentIndex: -1,
inputValue: ''
}
},
methods: {
handleClose(tag, index) {
this.dynamicTags[`tag${index}`].splice(this.dynamicTags[`tag${index}`].indexOf(tag), 1)
},
showInput(index) {
this.currentIndex = index
this.inputVisible = true
this.$nextTick(_ => {
this.$refs[`saveTagInput${index}`][0].$refs.input.focus()
})
},
handleInputConfirm(index) {
const inputValue = this.inputValue
if (inputValue) {
this.dynamicTags[`tag${index}`].push(inputValue)
}
this.inputVisible = false
this.currentIndex = -1
this.inputValue = ''
}
}
}
</script>
<style lang='scss' scpoed>
.app-container {
padding-bottom: 2rem;
.el-tag + .el-tag {
margin-left: 10px;
}
.button-new-tag {
margin-left: 10px;
height: 32px;
line-height: 30px;
padding-top: 0;
padding-bottom: 0;
}
.input-new-tag {
width: 90px;
margin-left: 10px;
vertical-align: bottom;
}
}
</style>
vue+element tag标签循环使用
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 前段时间本汪在制作高德地图时,在参照高德地图api时发现很多方法不能直接用,而官网并没有对此说明,度娘中也没有找到...
- 1.使用cue-cli 命令创建项目 2.导入Element UI 3.导入vue-x 3.1 在项目根目录下创建...
- 之前一直采用VS进行各种前端后端的开发,随着项目的需要,正逐步融合纯前端的开发模式,开始主要选型为Vue + El...
- 问题描述: 如何使用el-select标签及显示传递key的问题 如何将使用这个标签?如下图所示: 上面需要注意的...
- 直接用v-for是不可以的,参考了vue render 使用JSX实现 v-for ,都大同小异的