vue小白教程-4 想写啥写啥的小本本案例

需求分析:

功能需求:1.新增

                         新增列表结构 (用v-for和数组)

                         获取输入端数据(用v-model绑定)

                         按回车保存 (v-on.enter)

                   2.删除

                         v-on splice索引

                   3.统计

                         统计条数(v-textlength)

                   4.清空

                         点击清楚所有信息(v-on 删除数组)

                   5.隐藏

                         没数据时就隐藏(因为不频繁用v-if)

代码实现:

<!DOCTYPE html>
<html lang ="en">
<head>
    <meta charset="UFT-8">
    <meta name = "viewport" comtent ="width=device-width,initial-scale=1.0" >
    <meta http-equiv ="X-UA-Compatible" Content = "ie=edge">
    <title>实例:点击切换图片</title>
</head>

<body>
    <!--input bar-->
    <section id="todoapp">
        <header class="header">
            <h5>记事本</h5>
            <input v-model="inputValue" @keyup.enter="add" autofocus="autofocus" autocomplete="off" placeholder="想写啥写啥的小本本" class="new-todo" >
        </header>
          <!--table-->
          <section class="main">
              <ul class="todo-list">
                  <li class="todo" v-for="(item,index) in list">
                      <div class="view">
                          <span class="index">{{index +1}}.</span>
                          <label>{{ item }}</label>
                          <button class="destory" @click="remove(index)"></button>
                      </div>
                  </li>
              </ul>
          </section>
          <!--Statistics and empty-->
          <footer class="footer"></footer>
            <span class="todo-count"><strong>{{ list.length }}</strong> items left</span>
            <button v-if="list.length!=0" class="clear-completed" @click="clear">
                clear
                </button>
            </footer>
        </section>
  
  <!--bottom-->
  <footer class="info"></footer>


    <script  src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script>
        var app = new Vue({
            el:"#todoapp",
        data:{
           list:["哥斯拉",
           "猪血糕"],
           inputValue:"好好的"
        },
        motheds:{
            add:function(){
                this.list.push(this.inputValue);
            },
            remove:function(){
                console.log("删除");
                console.log(index);
                this.list.splice(index,1);
            },
            clear:function(){
                this.list=[];
            }
        },  
        })
    </script>
</body>
</html>

结果:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值