vue2.0 +Webpack 一个简单的todolist实例

用的vue-cli,这里就不写过程了,直接上代码吧!同样自己用webpack自己搭一个项目实例!

github地址:https://github.com/sky-xsk/vue2.0-start-
vue2.0写的项目:
https://github.com/sky-xsk/elem
如果有帮助,请给个star;

首先是html

<template>
  <div class="todo">
        <h2>todolist</h2>
        <div class="t_input">
            <span><input type="text"  class="t_titles"  placeholder="请输入。。。" v-model="text" @keyup.13="add()"></span>
            <span><button class="t_add" @click="add()">添加</button></span>
        </div>
        <div class="t-cont">
            <ul>
                <li v-for="(item,index) in todolist" track-by = "$index">
                     <input type="checkbox" v-model="item.state" class="checkbox"/>
                    {{`${index+1}. `}}  {{item.value}}
                    <span @click = "del(index)">删除</span>
                    <span @click = "edit(index)">编辑</span>
                </li>
                <div class="check_che" @click="remove()" v-show="select.length > 0" >删除选中</div>
                <p v-show="todolist.length == 0">暂无数据!</p>

            </ul>
        </div>    
  </div>
</template>

js


<script>
    export default {
        name: 'todo',
        data() {
            return {
                todolist:[], 
                text:'',
                state: false,
            }
        },
        methods:{
            //添加
            add(){
                if(this.text == ''){
                    return 
                }else{
                    this.todolist.push ({
                    value:this.text,
                    state: false,
                })
             }  
                this.text='';
            },
            //删除
            del(index){
                this.todolist.splice(index,1);
            },
            //删除选中
            remove(){
                this.todolist = this.todolist.filter((index) => !index.state)
            },
            //编辑
            edit(index){
                this.text = this.todolist[index].value;
                this.todolist.splice(index,1);
            }
        },
        //计算属性
         computed: {
            select() {
                return this.todolist.filter((index) => index.state == true)
            }
        }
    }
</script>

css


<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.t_titles{ width: 400px; height: 35px; font-size: 16px; padding-left: 10px;}
.t_add{ width: 60px; height:40px; font-size: 16px; vertical-align: middle;}
.t-cont{ width:100%; margin-top: 20px; margin: 0 auto;}
.t-cont ul li{list-style: none; height: 30px; border: 1px solid #ccc; line-height: 30px; text-align: left; padding-left: 10px;}
.t-cont ul li span{float: right; cursor: pointer; padding-right: 10px;}
.t-cont ul li input{padding-top: 5px;}
.checks{ width: 15px; height: 15px; border-radius:50%; border: 1px solid #ccc; display: inline-block;margin-top: 5px; cursor: pointer; }
.checkbox { width: 18px; height: 18px;border: 1px solid #ccc; border-radius: 100%; position: relative; margin-right: 6px; vertical-align: middle;  }
.checkbox:checked {border-color: deepskyblue;}
.checkbox:checked:before { content: ''; display: block; width: 80%; height: 80%; position: absolute; left: 50%; top: 50%;transform: translate(-50%, -50%); background: deepskyblue; border-radius: 100%;}
.check_che{border: 1px solid #ccc; padding:10px;}
</style>

效果如截图:

image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 前言 webpack2和vue2已经不是新鲜东西了,满大街的文章在讲解webpack和vue,但是很多内容写的不是...
    技术宅小青年阅读 6,601评论 4 43
  • “阅读只能为大脑提供知识的材料,只有经过思考才能将知识转为自己的思想。” 同理,画禅绕画也是一样的。将学习到的东西...
    卖眼镜的画画熊Rx阅读 294评论 2 2
  • 凌晨四点半,送我最爱的你去火车站,虽然知道今晚你就会回来,可是还是很难过,莫名很心酸…… 又要开始“异...
    凌漓阅读 159评论 1 0
  • 我一度羡慕热情的人,觉得她们轻易的得到了人际。然后,我开始责怪自己的寡淡,清高的安慰,我不希望自己刻意地讨好和无聊...
    梵文米娜阅读 406评论 3 1
  • <前文> 我的姐姐有一头乌黑亮丽的长发,性格是那么温婉动人,笑起来脸上会有浅浅的酒窝,可是,她死了. .........
    彭可欣阅读 1,038评论 3 2