使用Vue框架如何制作具有简单功能的记事本
Admin 2022-07-08 群英技术资讯 587 次浏览
本文实例为大家分享了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下的双向绑定功能,个人理解为在处理逻辑的过程中缓存了大量的node对象,node对象可以是html标签、文本内容。既然选择了缓存这些对象,那么在用的过程中哪里需要改变就把node拿出来,进行标签属性的变更或者文本内容的修改。本文主要讲了如何实现双向绑定
这篇文章主要为大家介绍了Vue3插槽Slot实现原理详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
本章节讨论使用ES6编码风格到代码中需要注意的点。通过记住这些关键点,可以让我们写出更优美的、可读性更强的JavaScript ES6风格的代码。
这篇文章主要介绍了在js中修改html body的样式,下面文章围绕js修改html 和body样式的相关资料展开详细内容,需要的朋友可以参考一下,希望对大家有所帮助
这篇文章给大家分享的是微信小程序中多图片上传效果的实现。小编觉得挺实用的,因此分享给大家做个参考,文中示例代码介绍的非常详细,感兴趣的朋友接下来一起跟随小编看看吧。
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008