国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

ElementUI Tag組件實現多標簽生成的方法示例

2019-11-19 11:13:06
字體:
來源:轉載
供稿:網友

現在好多應用場景里會有一些需要給文章打標簽等類似的操作,之前jquery用戶是使用taginput來實現,使用VUE以后elementui有一個組件非常簡單就是tag組件。

<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">+ New Tag</el-button><style> .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><script> export default {  data() {   return {    dynamicTags: ['標簽一', '標簽二', '標簽三'],    inputVisible: false,    inputValue: ''   };  },  methods: {   handleClose(tag) {    this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1);   },   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>

這個是官方文檔給的實例,這樣可以解決單一標簽輸入。但是實際場景中,好多用戶是通過ctrl+c,ctrl+v的方式輸入的,有可能還會一起粘貼好多行的標簽,更有可能從excel中復制出來。

那我一一解決一下這樣一個場景

首先,先改一下樣式,讓文本框變長:

.el-tag{ margin-right: 10px;}.el-tag + .el-tag {  margin-right: 10px; } .button-new-tag {  height: 32px;  line-height: 30px;  padding-top: 0;  padding-bottom: 0; } .input-new-tag {  vertical-align: bottom; }

接著,修改一下enter和blur事件:

handleInputConfirm() { let inputValue = this.inputValue;  if (inputValue) {   var values = inputValue.split(/[,, /n]/).filter(item=>{    return item!='' && item!=undefined   })   values.forEach(element => {    var index = this.dynamicTags.findIndex(i=>{    return i==element   })   if(index<0){    this.dynamicTags.push(element);   }  });    } this.inputVisible = false; this.inputValue = '';}

效果:

阿大發
asd

三大發舒服,

阿斯頓發撒地方。
阿斯頓發,阿斯頓發,,阿斯頓發,,阿斯頓發安撫,阿斯頓發 是淡淡的  點點滴滴方法,阿斯頓發撒地方,adfasd

我們把以上文字復制粘貼進去

 

所有去重,拆分都OK,那們在試一下,從excel中復制

 

完成。希望能夠幫到有需要的朋友。也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 涿鹿县| 阜阳市| 桂林市| 吴忠市| 潞城市| 龙陵县| 云浮市| 阿合奇县| 六盘水市| 巩留县| 集安市| 高密市| 金溪县| 聊城市| 义乌市| 淮滨县| 武夷山市| 龙游县| 廉江市| 永吉县| 东安县| 达拉特旗| 石景山区| 永顺县| 黎川县| 珲春市| 汝南县| 萍乡市| 罗甸县| 垫江县| 灵山县| 高唐县| 肃北| 微山县| 台州市| 黄石市| 定陶县| 大丰市| 株洲县| 江达县| 通江县|