vue实现添加标签demo示例代码
作者:虎嗅添香 发布时间:2024-05-21 10:14:49
标签:vue,标签
本篇文章主要介绍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:'开发语法'}, {name: '系统设备'}],
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});
}
}
});
来源:https://segmentfault.com/a/1190000008170838


猜你喜欢
- 如何引入同级包和模块工程项目结构如下包AnimalShow和Class_test是同级包,AnimalShow是父类,Gound,Sea,S
- 本文实例为大家分享了python实现简单tftp的具体代码,供大家参考,具体内容如下tftp是基于udp的协议实现简单的tftp,首先要有t
- 前言本文使用 cpu 版本的 tensorflow 2.4 ,选用 Keras Tuner 工具以 Fashion 数据集的分类任务为例,完
- 这个游戏就是实现键盘上输入不同的数字,将圆分割成不同的几个部分,每部分用不同的颜色来实现。导入包导入随机包,pygame,系统包,time时
- 本文主要介绍了MySQL8.0.27安装过程中卡在Initializing Database中并报错的解决,具有一定的参考价值,具体如下:报
- Web 前端优化最佳实践第三部分面向 Cookie 。目前只有 2 条实践规则。1. 缩小 Cookie (Reduce Cook
- Oracle当然是世界上最强大的数据库,但它的客户端sqlplus真的不友好,现在还不能支持上下方向键翻查历史命令,这里介绍使用readli
- 引言作为一个web前端开发,对axios肯定不陌生,但是在前端开发中,一般是使用axios来请求后端接口,获取数据。而使用node+axio
- 语法糖内的defineProps及defineEmits1、defineProps获取组件传值<div :style="fo
- 方法一:import osimport cv2 as cvimport numpy as np# 读取yuv420p的一帧文件,并转化为pn
- 本文主要讲如何不依赖TenserFlow等高级API实现一个简单的神经网络来做分类,所有的代码都在下面;在构造的数据(通过程序构造)上做了验
- 本文实例讲述了layer弹窗插件操作方法。分享给大家供大家参考,具体如下:1、首先去http://layer.layui.com/下载插件2
- 触发器是一种特殊类型的存储过程,它不同于之前的我们介绍的存储过程。触发器主要是通过事件进行触发被自动调用执行的。而存储过程可以通过存储过程的
- ASP.net处理文件上传就简单的多了,我呢也是在学习中,顺便写写学习笔记。 先在表单中添加enctype="multipart/
- 1、什么是路由懒加载官方的解释:当打包构建应用时,JavaScript 包会变得非常大,影响页面加载。如果我们能把不同路由对应的组件分割成不
- 目录输出算法操作封装的操作含时演化算符的分解QFT的分解总结概要输出算法操作首先介绍一个最基本的使用方法,就是使用ProjectQ来打印量子
- 我就废话不多说了,大家还是直接看代码吧!import requestsimport jsonraw = {}headers中添加上conte
- 本文实例为大家分享了python交互式图形编程实例的第三部代码,供大家参考,具体内容如下#!/usr/bin/env python3# -*
- 关于SQL Server 2014中的基数估计,官方文档Optimizing Your Query Plans with the SQL S
- 环境:vue 2.9.3; webpack目的:接口的调用跨域方式:1、express中间的使用2、nginx代理3、谷歌浏览器跨域设置--