1. 程式人生 > >vue(三)vue簡單todo demo

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>