您的位置:首页 > 其它

IMWeb训练营作业1-todolist

2017-04-20 13:42 701 查看

运行效果图:



HTML代码:

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>todo-list</title>

<link href="main.css" rel="stylesheet" type="text/css">

<script src="vue.js"></script>

</head>

<body>

  <div class="top">

    <div class="title">

      <h2>任务计划列表</h2>

    </div>

  </div>

  <div class="content">

    <h3 class="big_title">添加任务</h3>

    <input

    type="text"

    placeholder="例如:吃饭睡觉打豆豆; 提示:+回车即可添加任务"

    class="add_input"

    v-on:keyup.enter="addEvent"

    v-model="todo"

    />

    <ul class="add_task" v-show="list.length">

      <li>{{ noCheckeLength }}个任务未完成</li>

      <li class="action">

      <a class="active" href="#">所有任务</a>

      <a href="#">未完成的任务</a>

      <a href="#">完成的任务</a></li>

    </ul>

    <h3 class="big_title">任务列表</h3>

    <div class="tasks">

      <span class="no_task" v-show="!list.length">还没有添加任何任务</span>

      <ul class="todo_list">

        <li class="todo" :class="{completed: item.isChecked,editing:item==edtorTodos}" v-for="item in list">

          <div class="view">

            <input  class="option" type="checkbox" v-model="item.isChecked"/>

             <label @dblclick="edtorTodo(item)">{{ item.title }}</label>

             <button class="del" @click="deleteTodo(item)"></button>

          </div>

          <input

          v-foucs="edtorTodos==item"

          @blur="edtorTodoed(item)"

          @keyup.enter="edtorTodoed(item)"

          @keyup.esc="cancelTodo(item)"

           class="edit"

           type="text"

           v-model="item.title"

           />

          </li>

      </ul>

    </div>

  </div>

  <script src="app.js"></script>

</body>

</html>

CSS代码:

body {

    margin:0;

    background-color: #fafafa;

    font: 14px 'Helvetica Neue', Helvetica, Arial, sans-serif;

}

h2{

    margin:0;

    font-size: 12px;

}

a {

    color: #000;

    text-decoration: none;

}

input {

    outline: 0;

}

button {

    margin: 0;

    padding: 0;

    border: 0;

    background: none;

    font-size: 100%;

    vertical-align: baseline;

    font-family: inherit;

    font-weight: inherit;

    color: inherit;

    outline: 0;

}

ul {

    padding:0;

    margin:0;

    list-style: none;

}

.top {

    width: 100%;

    height: 40px;

    background-color: #db4c3f;

}

.title {

    width: 50%;

    margin: 0px auto;

}

.title h2{

    line-height: 40px;

    font-size: 18px;

    color: #fff;

}

.content {

    width: 50%;

    margin: 0px auto;

    box-sizing:border-box;

}

.add_input {

    width: 99%;

    height:30px;

    outline: 0;

    border: 1px solid #ccc;

}

.add_task{

    display: flex;

    margin:10px 0;

}

.add_t
4000
ask li {

    padding-left: 10px;

    flex: 1;

    color: #dd4b39;

}

.add_task li:nth-child(1){

    padding: 5px 0 0 10px;

}

.action {

    text-align: center;

    display: flex;

}

.action a {

    margin: 0px 10px;

    flex: 1;

    padding: 5px 0;

    color: #777;

}

.action a:nth-child(3){

    margin-right: 0;

}

.active {

    border: 1px solid rgba(175, 47, 47, 0.2);

}

.tasks {

    background-color: #fff;

}

.no_task {

    padding:10px 0 10px 10px;

    display: block;

    border-bottom: 1px solid #ededed;

    color:#777;

}

.big_title {

    color: #222;

}

.todo_list {

    margin: 0;

    padding: 0;

    list-style: none;

}

.todo_list li {

    position: relative;

    font-size: 16px;

    border-bottom: 1px solid #ededed;

}

.todo_list li:hover {

    background-color: #fafafa;

}

.todo_list li.editing {

    border-bottom: none;

    padding: 0;

}

.todo_list li.editing .edit {

    display: block;

    width: 506px;

    padding: 13px 17px 12px 17px;

    margin: 0 0 0 43px;

}

.todo_list li.editing .view {

    display: none;

}

.todo_list li .toggle {

    text-align: center;

    width: 40px;

    /* auto, since non-WebKit browsers doesn't support input styling */

    height: auto;

    position: absolute;

    top: 5px;

    bottom: 0;

    margin: auto 0;

    border: none; /* Mobile Safari */

    -webkit-appearance: none;

    appearance: none;

}

.option {

    text-align: center;

    width: 40px;

    /* auto, since non-WebKit browsers doesn't support input styling */

    height: auto;

    position: absolute;

    top: 5px;

    bottom: 0;

    margin: auto 0;

    border: none; /* Mobile Safari */

    -webkit-appearance: none;

    appearance: none;

}

 .option:after {

    content: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="-10 -18 100 135"><circle cx="50" cy="50" r="40" fill="none" stroke="#ededed"
stroke-width="3"/></svg>');

}

.option:checked:after {

    content: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="-10 -18 100 135"><circle cx="50" cy="50" r="40" fill="none" stroke="#bddad5"
stroke-width="3"/><path fill="#5dc2af" d="M72 25L42 71 27 56l-4 4 20 20 34-52z"/></svg>');

}

.todo_list li label {

    white-space: pre-line;

    word-break: break-all;

    padding: 15px 60px 15px 15px;

    margin-left: 45px;

    display: block;

    line-height: 1.2;

    transition: color 0.4s;

}

.todo_list li.completed label {

    color: #d9d9d9;

    text-decoration: line-through;

}

/*.tip-toggle {

    padding-left: 0;

    position: relative;

}

.tip-toggle .toggle {

    top: -2px;

}

.tip-toggle span {

    margin-left: 45px;

}*/

.todo_list li .del {

    display: none;

    position: absolute;

    top: 0;

    right: 10px;

    bottom: 0;

    width: 40px;

    height: 40px;

    margin: auto 0;

    font-size: 30px;

    color: #cc9a9a;

    margin-bottom: 11px;

    transition: color 0.2s ease-out;

}

.todo_list li .del:hover {

    color: #af5b5e;

}

.todo_list li .del:after {

    content: '×';

}

.todo_list li:hover .del {

    display: block;

}

.todo_list li .edit {

    display: none;

}

.todo_list li.editing:last-child {

    margin-bottom: -1px;

}

JS代码:

// JavaScript Document

var list = [

    { title:"吃饭打豆豆",

     isChecked:false//状态为false,为不选中,任务未完成

 },

     { title:"吃饭睡觉打豆豆",

     isChecked:true//状态为true,为选中,任务完成

 },

];

new Vue({

 el:".content",

 data:{

   list:list,

   todo:"",

   edtorTodos:'',//记录正在编辑的数据

   beforeTitle:''//记录正在编辑的数据的title

   },

     computed:{

     noCheckeLength:function(){

      return this.list.filter(function(item){

                return !item.isChecked

               }).length

     }

   },

  methods:{

       addEvent(ev){//添加事件

    

     this.list.push({

      title:this.todo,

      isChecked:false

      });

      this.todo = '';

     },

        deleteTodo(todo){//删除任务

           var index = this.list.indexOf(todo);

     this.list.splice(index,1);

     },

        edtorTodo(todo){//编辑任务

     

     this.beforeTitle=todo.title;

     this.edtorTodos=todo;

    

     },

        edtorTodoed(todo){//编辑任务成功

      this.edtorTodos='';

     },

     cancelTodo(todo){//取消编辑任务

         todo.title=this.beforeTitle;

      this.beforeTitle='';

      //让div显示出来,input隐藏

      this.edtorTodos='';

     }

   },

   directives:{

    "foucs":{

     update(el,binding){

     

      if(binding.value){

       el.focus();

       }

      }

     }

   }

});

照着课程视频做了一遍,虽然很多东西还不熟练,收获还是不小的
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: