zsydgithub vor 2 Jahren
Ursprung
Commit
c4f4521438
1 geänderte Dateien mit 89 neuen und 0 gelöschten Zeilen
  1. 89 0
      10_vue/5_todolist.html

+ 89 - 0
10_vue/5_todolist.html

@@ -0,0 +1,89 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="UTF-8">
+  <meta http-equiv="X-UA-Compatible" content="IE=edge">
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  <title>Document</title>
+  <style>
+    #app{
+      width: 500px;
+    }
+    .close{
+      float: right;
+    }
+  </style>
+</head>
+<body>
+  <div id="app">
+    <h2>todolist</h2>
+    <hr>
+    <div>
+      名称:<input type="text" v-model="name">
+      价格:<input type="text" v-model="price">
+      <button @click="add">提交</button>
+    </div>
+    <div>
+      <input type="text" v-model="seachVal">
+      <button @click="search()">搜索</button>
+    </div>
+    <ul>
+      <li v-for="(obj,index) in list" v-show="obj.isShow">
+        <input type="checkbox">
+        <span>{{obj.name}}</span>
+        <span>{{obj.price}}</span>
+        <span class="close" @click="del(index)">[X]</span>
+      </li>
+    </ul>
+    <div>
+      <button>删除选择</button>
+      <span>总价</span>
+    </div>
+  </div>
+  <script src="vue.js"></script>
+  <script>
+    new Vue({
+      el:"#app",
+      data:{
+        list:[{
+          name:'苹果',
+          price:5,
+          isShow: true
+        },{
+          name:'香蕉',
+          price:6,
+          isShow: true
+        }],
+        name:'',
+        price:'',
+        seachVal:''
+      },
+      methods:{
+        add(){
+          this.list.push({
+            name: this.name,
+            price: this.price,
+            isShow: true
+          })
+          this.name = ''
+          this.price = ''
+        },
+        del(index){
+          this.list.splice(index,1)
+        },
+        search(){
+          this.list.forEach((obj)=>{
+            if(obj.name.includes(this.seachVal)){
+              obj.isShow = true
+            } else {
+              obj.isShow = false
+            }
+          })
+          this.seachVal = ''
+        }
+        
+      }
+    })
+  </script>
+</body>
+</html>