Vue待办事件 实时留言事件

vue待办事项

在这里插入代码片<template>
  <div class="about">
    <input type="text" v-model="inputvalue" />

    <button @click="submit">提交</button>
    <h3>未完成 ({{nolist.length}})</h3>

    <ul id="q1">
      <li v-for="(item,index) in nolist" :key="index">
        <input type="checkbox" @click.prevent="changeYes($event,item,index)" />
        {{item.text}} &nbsp;&nbsp; {{item.time|timeFilter}}&nbsp;&nbsp;
        <button
          @click="update(index)"
        >修改</button>&nbsp;&nbsp;&nbsp;&nbsp;
        <button @click="del(index)">删除</button>
      </li>
    </ul>
    <h3>已完成 ({{yeslist.length}})</h3>
    <ul>
      <li v-for="(item,index) in yeslist" :key="index">
        <input checked type="checkbox" @click.prevent="changeNo($event,item,index)" />

        {{item.text}} &nbsp;&nbsp;{{item.time|timeFilter}}&nbsp;&nbsp;
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  filters: {
    timeFilter(ms) {
      let dayStr = "";
      let date = new Date();
      let now = date.getTime();

      let rel = (now - ms) / 1000 / 60;

      if (rel <= 1) {
        dayStr = "刚刚";
      } else if (rel <= 3) {
        dayStr = "2分钟前";
      }
      return dayStr;
    }
  },

  data() {
    return {
      inputvalue: "",
      yeslist: [],
      nolist: []
    };
  },
  methods: {
    submit() {
      this.nolist.push({
        text: this.inputvalue,
        time: new Date().getTime()
      });
      this.inputvalue = "";
      // localStorage.yeslist = JSON.stringify(this.yeslist); //同步数据
    },
    changeYes(e, item, index) {
      let checked = e.target.checked;
      if (checked) {
        this.yeslist.push(item);
        this.nolist.splice(index, 1);
      }
      
    },
    changeNo(e, item, index) {
      let checked = e.target.checked;
      if (!checked) {
        this.nolist.push(item);
        this.yeslist.splice(index, 1);
      }
    },
    update(index) {
      let val = window.prompt("输入内容:");
      let obj = this.nolist[index];
      obj.text = val;
      this.nolist.splice(index, 1, obj);
    },
    del(index) {
      this.nolist.splice(index, 1);
    },
    getParseTime(ms) {
      let date = new Date();
      date.setTime(ms);
      let timeStr = `${date.getFullYear()}-${date.getMoth() + 1}-${
        date.getDate
      }${date.getHours()}:
                ${date.getMinutes()}:
                ${date.getSeconds()}`;
      return timeStr;
    }
    // created() {
    //   let yeslist = localStorage.yeslist;
    //   if (yeslist !== undefined) {
    //     this.yeslist = JSON.parse(yeslist);
    //   }
    // }
  }
};
</script>
<style lang="stylus" scoped></style>

在这里插入图片描述

Vue 待办事项 真实提交实时时间`

template>
  <div id="root">
    <input type="text" v-model="inputvalue"  id="inputvalue" @keydown.enter="submit">
    <button @click="submit" >提交</button>
    <ul id="q1">
<li
      v-for="(item,index) in list"
        :key="index"
      >{{item.text}}&nbsp;&nbsp;&nbsp;&nbsp;{{item.time|timeFilter}}</li>
    </ul>
  </div>
</template>

<script>
export default {
  data() {
    return {
      inputvalue: "",
      list: []
    };
  },
  filters: {
    timeFilter(ms) {
      let datStr = "";
      let date = new Date(); //获取当前时间
      let now = date.getTime();
      let rel = (now - ms) / 1000 / 60; //单位分钟
      if (rel <= 1) {
        datStr = "刚刚";
      } else if (rel <= 2) {
        datStr = "1分钟前";
      } else if (rel <= 3) {
        datStr = "2分钟前";
      } else if (rel <= 5) {
        datStr = "4分钟前";
      } else{
          datStr="把我存了这么久快把我拿走吧"
      }
      return datStr;
    }
  },

  created() {
    //初始化方法
    let list = localStorage.list;
    if (list != undefined) {
      this.list = JSON.parse(list);
    }
  },

  methods: {
    submit() {
      this.list.push({
        text: this.inputvalue,
        time: new Date().getTime()
      });
      this.inputvalue = "";

      localStorage.list = JSON.stringify(this.list); //同步保存数据
    }
  }
};
</script>

<style>
</style>

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

张清悠

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值