51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

vue开发小应用:简易记事本功能

vue开发小应用:简易记事本功能。我们可以先看下效果图:

20211203093742.jpg

功能:

输入任务的时候,按回车,下面直接登记任务。我们可以选择删除或者清空,然后重新进行登记。

废话不多说,直接上DEMO:

<!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>vue开发小应用:简易记事本功能 | Web前端之家https://www.jiangweishan.com/</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="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/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>

大家试试吧!

赞(0)
未经允许不得转载:工具盒子 » vue开发小应用:简易记事本功能