vue(三)vue简单todo demo

<html>

<head>
  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
  <title>hello</title>
</head>

<body>
  <div id="app">
    <input type="text" v-model="val" @keyup.enter=add>
    <ul>
      <li v-for="(a,index) in arr">{{a}} <button @click=remove(index)>删除</button></li>
    </ul>

  </div>
  <!-- <script src="node_modules\vue\dist\vue.js"></script> -->
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
  <script>
    let vm = new Vue({
      el: '#app',
      methods:{
        add(e){
            this.arr.unshift(this.val);
            this.val = '';
          },
            remove(val){
              this.arr=this.arr.filter((item,index)=>index != val);
            }
      },
      data: {
        arr:[],
        val: ''
      }
    })
  </script>

</body>

</html>

猜你喜欢

转载自blog.csdn.net/q975583865/article/details/84637837