使用Vue框架如何制作具有简单功能的记事本
Admin 2022-07-08 群英技术资讯 982 次浏览
今天这篇我们来学习和了解“使用Vue框架如何制作具有简单功能的记事本”,下文的讲解详细,步骤过程清晰,对大家进一步学习和理解“使用Vue框架如何制作具有简单功能的记事本”有一定的帮助。有这方面学习需要的朋友就继续往下看吧!本文实例为大家分享了Vue实现简易记事本功能的具体代码,供大家参考,具体内容如下
预览图:


功能如下:
(1)输入任务并按下回车键,可将任务添加至任务列表(不可输入重复任务)
(2)点击删除,可删除对应任务
(3)点击清空,所有任务都会被删除
(4)左下角同步显示任务总数
完整代码如下:
<!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>记事本</title>
<style>
* {
margin: 0;
padding: 0;
}
#todoapp {
width: 600px;
background-color: rgba(19, 161, 114, 0.63);
font-family: sans-serif;
}
.header>h1 {
padding: 20px 0;
text-align: center;
font-size: 40px;
color: whitesmoke;
}
.newTask {
display: block;
width: 500px;
height: 50px;
line-height: 50px;
padding-left: 10px;
margin: 0 auto;
font-size: 20px;
outline: none;
border: none;
}
.todolist li {
height: 30px;
line-height: 30px;
padding-left: 15px;
margin: 10px 0;
font-size: 25px;
color: white;
}
.todolist .item {
margin-left: 15px;
}
.destroy,
.clear {
width: 50px;
height: 30px;
float: right;
color: white;
background-color: transparent;
border: none;
font-size: 20px;
}
.footer {
width: 600px;
height: 30px;
padding: 10px 0;
vertical-align: middle;
}
.footer p {
display: inline-block;
padding-left: 15px;
color: white;
font-size: 20px;
}
</style>
</head>
<body>
<section id="todoapp">
<header class="header">
<h1>记事本</h1>
<input type="text" v-model="newItem" class="newTask" placeholder="请输入任务" @keyup.enter="add">
</header>
<section>
<ul class="todolist">
<li v-for="(item, index) in list">
<div>
<span>{{ index + 1 }}</span>
<label class="item">{{ item }}</label>
<button class="destroy" @click="del(index)">删除</button>
</div>
</li>
</ul>
</section>
<footer class="footer">
<p class="count">
items: {{ list.length }}
</p>
<button class="clear" @click="clear" v-show="list.length != 0">清空</button>
</footer>
</section>
<script src="./vue.js"></script>
<script>
const app = new Vue({
el: "#todoapp",
data: {
list: [],
newItem: ""
},
methods: {
add() {
if (this.newItem == "") {
return;
}
else {
if (!this.list.includes(this.newItem)) {
this.list.push(this.newItem);
this.newItem = "";
}
else {
alert("请勿添加重复事件!");
this.newItem = "";
}
}
},
del(index) {
this.list.splice(index, 1);
},
clear() {
this.list = [];
}
}
})
</script>
</body>
</html>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
这篇文章主要为大家介绍了Vue element树形控件添加虚线,具有一定的参考价值,感兴趣的小伙伴们可以参考一下,希望能够给你带来帮助<BR>
这篇文章主要介绍了Vue3.0 自己实现放大镜效果案例讲解,本篇文章通过简要的案例,讲解了该项技术的了解与使用,以下就是详细内容,需要的朋友可以参考下
这篇文章主要介绍了JS实现页面侧边栏效果探究,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
这篇文章我们来了解JS中如何隐藏html标签,一些朋友想要隐藏html标签,那么有什么方法可以实现呢?下文给大家分享了一个示例,文中的示例代码介绍得很详细,有需要的朋友可以参考,接下来就跟随小编一起了解看看吧。
本文我们来了解vant的picker组件的基本用法,下文示例对大家学习picker组件的使用有一定的帮助,需要的朋友可以参考。另外,本文还介绍了vant-ui的Field输入框和Picker结合使用时,如何绑定正确的id类型的值的问题,感兴趣的朋友也可以了解看看。
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
7x24小时售前:400-678-4567
7x24小时售后:0668-2555666
24小时QQ客服
群英微信公众号
CNNIC域名投诉举报处理平台
服务电话:010-58813000
服务邮箱:service@cnnic.cn
投诉与建议:0668-2555555
Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 ICP核准(ICP备案)粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008