| | |
| | | <template> |
| | | <div> |
| | | <el-button v-if="!inputVisible" class="button-new-tag" size="small" @click="showInput">+ 标签</el-button> |
| | | <el-input |
| | | v-else |
| | | class="input-new-tag" |
| | | v-model="inputValue" |
| | | ref="saveTagInput" |
| | | size="small" |
| | | @keyup.enter.native="handleInputConfirm" |
| | | @blur="handleInputConfirm" |
| | | > |
| | | </el-input> |
| | | <div class="tags-container"> |
| | | <el-tag |
| | | v-for="tag in dynamicTags" |
| | | :key="tag" |
| | | closable |
| | | :disable-transitions="false" |
| | | @close="handleClose(tag)"> |
| | | {{tag}} |
| | | </el-tag> |
| | | <div> |
| | | <el-button v-if="!inputVisible" class="button-new-tag" size="small" @click="showInput">+ 标签</el-button> |
| | | </div> |
| | | <div> |
| | | <el-input |
| | | v-if="inputVisible" |
| | | class="input-new-tag" |
| | | v-model="inputValue" |
| | | ref="saveTagInput" |
| | | size="small" |
| | | @keyup.enter.native="handleInputConfirm" |
| | | @blur="handleInputConfirm" |
| | | > |
| | | </el-input> |
| | | <div class="tags-container"> |
| | | <el-tag |
| | | v-for="(tag, index) in tags" |
| | | :key="tag + index" |
| | | closable |
| | | @close="handleClose(index)"> |
| | | {{tag}} |
| | | </el-tag> |
| | | </div> |
| | | </div> |
| | | |
| | | </div> |
| | | </template> |
| | | |
| | | <script> |
| | | export default { |
| | | props: { |
| | | tagList: { |
| | | required: true, |
| | | type: Array |
| | | } |
| | | }, |
| | | watch: { |
| | | tagList(newV, oldV) { |
| | | this.tags = newV |
| | | } |
| | | }, |
| | | data() { |
| | | return { |
| | | dynamicTags: ['重点标记', '发改关注', '年度项目'], |
| | | tags: [], |
| | | inputVisible: false, |
| | | inputValue: '' |
| | | }; |
| | | }, |
| | | methods: { |
| | | handleClose(tag) { |
| | | this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1); |
| | | setTags(list) { |
| | | this.tags = list; |
| | | }, |
| | | handleClose(index) { |
| | | console.log("点了") |
| | | this.tags.splice(index, 1); |
| | | this.$emit("getTags", this.tags) |
| | | }, |
| | | |
| | | showInput() { |
| | |
| | | handleInputConfirm() { |
| | | let inputValue = this.inputValue; |
| | | if (inputValue) { |
| | | this.dynamicTags.push(inputValue); |
| | | this.tags.push(inputValue); |
| | | this.$emit("getTags", this.tags) |
| | | } |
| | | this.inputVisible = false; |
| | | this.inputValue = ''; |