类似愿望清单

加油加油加油

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>心愿清单</title>
<style>
* {
    margin: 0;
    padding: 0;
    border: 0;
}
body {
    background: #f0f0f0;
    font-size: 18px;
}
input {
    box-sizing: border-box;
    width: 100%;
    height: 30px;
    padding: 0 10px;
    border: 1px solid #666;
    font-size: 18px;
}
.wish {
    padding: 30px;
}
ul {
    margin: 20px 0;
    list-style: none;
}
li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 40px;
}
.wish-btn {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    line-height: 50px;
    background: #ccc;
    text-align: center;
}
.modal {
    position: fixed;
    top: 0; right: 0;
    bottom: 0; left: 0;
    background: rgba(0,0,0,.8);
    transform: translateX(100%);
    transition: .6s;
}
.modal.show {
    transform: translateX(0);
}
.modal .btn {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    line-height: 50px;
    background: #ccc;
    text-align: center;
    cursor: pointer;
}
.modal ul {
    position: absolute;
    right: 0;
    bottom: 50px;
    left: 0;
    margin: 0;
    padding: 10px 30px;
    background: #fff;
}
</style>
</head>
<body>
<div class="wish">
    <input
        placeholder="搜索"
        v-model.trim="keyword"
    >
    <ul>
        <li
            v-for="(d, i) in searchList"
            :key="i"
            @click="add(d)"
        >
            <p>{{ d }}</p>
            <span>+</span>
        </li>
    </ul>

    <div
        class="wish-btn"
        @click="showModal = true"
    >
        ❤️ 心愿清单({{ wishList.length }}) ❤️
    </div>

    <div
        class="modal"
        :class="{ 'show': showModal }"
        @click.self="showModal = false"
    >
        <ul>
            <li v-if="wishList.length === 0">暂无数据</li>
            <li
                v-for="(d, i) in wishList"
                :key="i"
                @click="toggle(i)"
            >
                <p :style="{ 'text-decoration': d.done ? 'line-through' : '', 'color': d.done ? 'gray' : '' }">{{ d.text }}</p>
                <span>{{ d.done ? '✓' : '✕' }}</span>
            </li>
        </ul>
        <div
            class="btn"
            @click="showModal = false"
        >关闭</div>
    </div>
</div>
<script src="./vue.min.js"></script>
<script>
new Vue({
    el: '.wish',
    data: {
        list: ['开火车','开跑车','找个好工作','杀死一只狮子','杀死一只骆驼','掌握Vue','搞定ES6'],
        wishList: [],
        showModal: false,
        keyword: ''
    },

    computed: {
        searchList() {
            const { keyword, list } = this;
            if (!keyword) return list;
            return list.filter(i => i.includes(keyword));
        }
    },

    methods: {
        add(text) {
            // 缺少判断,先判断是否在数组中存在,如果存在就不加了
            if (this.wishList.some(i => i.text === text)) return;
            this.wishList.push({
                text,
                done: false
            });
        },

        toggle(i) {
            this.wishList[i].done = !this.wishList[i].done;
        }
    }
});
</script>
</body>
</html>

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值