<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 ,都大同小异的