vue實(shí)現(xiàn)添加標(biāo)簽demo示例代碼
本篇文章主要介紹vue添加標(biāo)簽,廢話不多說了,下面上具體代碼
效果如下:
html
<div id="app"> <div style="margin-bottom: 4px;"> <span class="selectedItem" v-for="item in selectedItems">{{item.name}} <i class="red fa fa-close (alias)" v-on:click="deleteSelectedItem($index)"></i></span> <input v-model="inputItem" type="text" v-on:focus="showDropmenu" v-on:keyup.enter="addItem"> </div> <div v-show="isShowDropmenu"> <button v-for="item in cataName" v-on:click="showCataList($index)">{{item.name}}</button> <button v-on:click="hideDropmenu"><i class="red fa fa-close (alias)"></i></button> <div v-for="item in cataList" v-show="item.isShow"> <span v-for="one in item.items" class="item" v-on:click="addByClick(one)">{{one}}</span> </div> </div> </div>
js
new Vue({ el:'#app', data:{ selectedItems: [{ name: 'NodeJs' }], isShowDropmenu: false, inputItem:'', cataName:[{name:'開發(fā)語法'}, {name: '系統(tǒng)設(shè)備'}], cataList:[{ isShow: true, items:['js','c++','java'] },{ isShow: false, items:['windows','chrome','linux'] }] }, methods:{ showDropmenu: function(event){ console.log('showDropmenu'); this.isShowDropmenu = true; }, hideDropmenu: function(event){ this.isShowDropmenu = false; console.log('hideDropmenu'); }, test: function(){ console.log('test'); }, addItem: function(){ this.selectedItems.push({name: this.inputItem}); this.inputItem = ""; }, deleteSelectedItem: function(index){ this.selectedItems.splice(index, 1); }, showCataList: function(index){ var i = this.cataList.length; while(i--){ i === index ? this.cataList[i].isShow = true: this.cataList[i].isShow = false; } }, addByClick: function(name){ var i = this.selectedItems.length; while(i--){ if(this.selectedItems[i].name === name){ return; } } this.selectedItems.push({name: name}); } } });
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
解讀element-ui使用el-upload,before-upload函數(shù)不好使的問題
這篇文章主要介紹了解讀element-ui使用el-upload,before-upload函數(shù)不好使的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-03-03Vue 組件(component)教程之實(shí)現(xiàn)精美的日歷方法示例
組件是我們學(xué)習(xí)vue必須會(huì)的一部分,下面這篇文章主要給大家介紹了關(guān)于Vue 組件(component)教程之實(shí)現(xiàn)精美的日歷的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2018-01-01vue3中g(shù)etCurrentInstance不推薦使用及在<script?setup>中獲取全局內(nèi)容的三種方式
這篇文章主要給大家介紹了關(guān)于vue3中g(shù)etCurrentInstance不推薦使用及在<script?setup>中獲取全局內(nèi)容的三種方式,文中通過介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2024-02-02解決Vue運(yùn)行項(xiàng)目報(bào)錯(cuò)proxy?error:?could?not?proxy?request
這篇文章主要給大家介紹了關(guān)于如何解決Vue運(yùn)行項(xiàng)目報(bào)錯(cuò)proxy?error:could?not?proxy?request的相關(guān)資料,Proxy Error指的是代理服務(wù)器無法正確處理請(qǐng)求的錯(cuò)誤,需要的朋友可以參考下2023-08-08vue項(xiàng)目webpack中Npm傳遞參數(shù)配置不同域名接口
這篇文章主要介紹了vue項(xiàng)目webpack中Npm傳遞參數(shù)配置不同域名接口,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-06-06vue前端實(shí)現(xiàn)導(dǎo)出頁面為word的兩種方法代碼
在前端開發(fā)中我們常常需要將頁面頁面為word文件,這篇文章主要給大家介紹了關(guān)于vue前端實(shí)現(xiàn)導(dǎo)出頁面為word的兩種方法,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-04-04vue3+elementPlus?table中添加輸入框并提交校驗(yàn)
這篇文章主要介紹了vue3+elementPlus?table里添加輸入框并提交校驗(yàn),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-08-08vue在取對(duì)象長度length時(shí)候出現(xiàn)undefined的解決
這篇文章主要介紹了vue在取對(duì)象長度length時(shí)候出現(xiàn)undefined的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-06-06uniapp實(shí)現(xiàn)webview頁面關(guān)閉功能的代碼示例
uniapp用web-view打開一個(gè)網(wǎng)頁,網(wǎng)頁中點(diǎn)擊跳轉(zhuǎn)到下一層級(jí)的網(wǎng)頁,一層層深入,點(diǎn)擊返回鍵或者頁面上方返回按鈕只能一層層往回退,下面這篇文章主要給大家介紹了關(guān)于uniapp實(shí)現(xiàn)webview頁面關(guān)閉功能的相關(guān)資料,需要的朋友可以參考下2024-03-03