Todolist

227 阅读1分钟

请观赏

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="js/vue.min.js"></script>
    <style>
        ul>li>label{
            display: inline-block;
            width: 30px;
            height: 30px;
            background:red;
            text-align: center;
            line-height: 30px;
            color: white;

        }
        ul>li>input[type = "checkbox"]:checked+label{
            color: #ccc;
        }
    </style>
</head>
<body>
    <div id="app">
        <input type="text" v-model="tal" @keyup.enter="add">
        <hr>
        <p>正在进行</p>
            <ul>
                <li v-for="(item,key) in list" :key="key" v-show=!item.flag>
                    <input type="checkbox" v-model="item.flag" @change="save()"
                    :id="key">
                    <label :for="key">√</label>
                    <span v-show="!item.show" @click="change(key)">{{item.tal}}</span>
                    <input type="text" v-model="item.tal" v-show="item.show">
                </li>
            </ul>
        <p>已经完成</p>
            <ul>
                <li v-for="(item,key) in list" :key="key" v-show="item.flag" >
                        <input type="checkbox" v-model="item.flag" @change="save()"
                        :id="key">
                        <label for="key">√</label>
                    <span>{{item.tal}}</span>
                    <input type="text" v-model="item.tal" >
                </li>
            </ul>
    </div>
</body>
</html>
<script>
    var vm = new Vue({
        el:"#app",
        data:{
            tal:"",
            list:JSON.parse(localStorage.getItem("todo"))||[]
        },
        methods:{
            add(){
                if(this.tal==""){
                    return false
                }
                var obj = {
                    "tal":this.tal,
                    flag:false,
                    show:false
                }
                this.list.unshift(obj)
                localStorage.setItem("todo",JSON.stringify(this.list))
            },
            save(){
                localStorage.setItem("todo",JSON.stringify(this.list))
            },
            change(key){
                for(var i in this.list){
                    this.list[i].show = false
                }
                this.list[key].show = true
            }
        }
    })
</script>