前端Vue基础知识---实现简单todoListdemo

前端Vue基础知识—实现简单todoListdemo

v-mode : 双向数据绑定
v-for : 循环遍历数组对象数据
v-on:click = @click : 绑定执行事件
v-if : 对数据状态进行判断,从而决定执行
v-bind : 绑定属性变量(动态属性)
未完待续…

demo效果如下:
在这里插入图片描述
代码如下:

<template>
  <div id="app">
    
    <!-- todoList效果 -->
   <input type="text" v-model="todo" @keydown="addData($event)"/>
   <button @click="add()"> + </button>
   <br>
   <hr>
   <br>
   <h2>进行中</h2>
    <ul>
      <li v-for="(item,key) in list" v-if="!item.checked">
         <input type="checkbox" v-model="item.checked"/> {{item.title}} ------ <button 		  @click="removeData(key)"> - </button>
      </li>
    </ul>
    <br>
    <hr>
    <br>
    <h2>已完成</h2>
    <ul>
      <li v-for="(item,key) in list" v-if="item.checked">
         <input type="checkbox" v-model="item.checked"/> {{item.title}} ------ <button @click="removeData(key)"> - </button>
      </li>
    </ul>

  </div>
</template>

<script>
export default {
  name: 'App',
  data(){
    return{
      todo:'',
      list:[]
    }

  },
  methods:{
    add(){
        this.list.push({
        title:this.todo,
        checked:false
      });
      this.todo='';
    },
    addData(e){
      if(e.keyCode===13){
        this.list.push({
        title:this.todo,
        checked:false
      });
      }
      this.todo='';
    },
    removeData(key){
      this.list.splice(key,1)
    }
  }
}
</script>

<style>
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
.red{
  color: red
}
.blue{
  color: blue
}
.box{
  width: 100px;
  height: 100px;
  background: lightcoral;
}
</style>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值