vue實現(xiàn)添加標簽demo示例代碼
本篇文章主要介紹vue添加標簽,廢話不多說了,下面上具體代碼
效果如下:

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)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
解讀element-ui使用el-upload,before-upload函數(shù)不好使的問題
這篇文章主要介紹了解讀element-ui使用el-upload,before-upload函數(shù)不好使的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-03-03
Vue 組件(component)教程之實現(xiàn)精美的日歷方法示例
組件是我們學習vue必須會的一部分,下面這篇文章主要給大家介紹了關(guān)于Vue 組件(component)教程之實現(xiàn)精美的日歷的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧。2018-01-01
vue3中g(shù)etCurrentInstance不推薦使用及在<script?setup>中獲取全局內(nèi)容的三種方式
這篇文章主要給大家介紹了關(guān)于vue3中g(shù)etCurrentInstance不推薦使用及在<script?setup>中獲取全局內(nèi)容的三種方式,文中通過介紹的非常詳細,對大家的學習或者工作具有一定的參考借鑒價值,需要的朋友可以參考下2024-02-02
解決Vue運行項目報錯proxy?error:?could?not?proxy?request
這篇文章主要給大家介紹了關(guān)于如何解決Vue運行項目報錯proxy?error:could?not?proxy?request的相關(guān)資料,Proxy Error指的是代理服務(wù)器無法正確處理請求的錯誤,需要的朋友可以參考下2023-08-08
vue項目webpack中Npm傳遞參數(shù)配置不同域名接口
這篇文章主要介紹了vue項目webpack中Npm傳遞參數(shù)配置不同域名接口,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-06-06
vue前端實現(xiàn)導(dǎo)出頁面為word的兩種方法代碼
在前端開發(fā)中我們常常需要將頁面頁面為word文件,這篇文章主要給大家介紹了關(guān)于vue前端實現(xiàn)導(dǎo)出頁面為word的兩種方法,文中通過代碼介紹的非常詳細,需要的朋友可以參考下2024-04-04
vue3+elementPlus?table中添加輸入框并提交校驗
這篇文章主要介紹了vue3+elementPlus?table里添加輸入框并提交校驗,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-08-08
vue在取對象長度length時候出現(xiàn)undefined的解決
這篇文章主要介紹了vue在取對象長度length時候出現(xiàn)undefined的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-06-06
uniapp實現(xiàn)webview頁面關(guān)閉功能的代碼示例
uniapp用web-view打開一個網(wǎng)頁,網(wǎng)頁中點擊跳轉(zhuǎn)到下一層級的網(wǎng)頁,一層層深入,點擊返回鍵或者頁面上方返回按鈕只能一層層往回退,下面這篇文章主要給大家介紹了關(guān)于uniapp實現(xiàn)webview頁面關(guān)閉功能的相關(guān)資料,需要的朋友可以參考下2024-03-03

