Vue小项目01——标签记录器
Vue小项目——标签记录器
功能:用户在文本框里输入文本,按回车键,文本添加到信息栏里,并清空文本框里的内容,最左侧有信息编号,下方有所以信息条数,每条信息右测有删除叉,最下方有全部清空按钮,当信息全部清空,最下方一栏将隐藏。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js" integrity="sha384-t1tHLsbM7bYMJCXlhr0//00jSs7ZhsAhxgm191xFsyzvieTMCbUWKMhFg9I6ci8q" crossorigin="anonymous"></script>
<style>
body{
padding:0;
margin: 0;
}
.divcenter{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
width: 500px;
height: 50%;
}
p{
border: solid 1px;
margin: 0px;
padding: 0px;
}
.spanX{
float:right;
margin-right: 10px;
width: 10px;
}
span{
cursor: pointer;
}
h2{
text-align: center;
}
</style>
</head>
<body>
<div id="app" class="divcenter">
<h2>标签记录器</h2>
<div>
<input type="text" placeholder="请输入相应信息后按回车键!" v-model="text" @keyup.Enter="info" style="width: 100%;height: 40px;">
</div>
<div>
<p v-for="(list,index) in arr">
<span style="background-color: blanchedalmond;"> {{index+1}} </span> {{list}}
<span class="spanX" @click="del(index)">x</span>
</p>
<div style="border: solid 1px;" v-show="arr.length!=0">
<span>总数:{{arr.length}}</span>
<span style="float: right;" @click="delAll">Clear</span>
</div>
</div>
</div>
<script>
var app=new Vue({
el:"#app",
data:{
arr:[],
text:"",
},
methods:{
info:function(){
this.arr.push(this.text);
this.text="";
},
del:function(index){
this.arr.splice(index,1);
} ,
delAll:function(){
this.arr=[];
}
}
})
</script>
</body>
</html>
本文来自博客园,作者:永恒之月TEL,转载请注明原文链接:https://www.cnblogs.com/akc4/p/16074373.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步