zsydgithub 1 tahun lalu
induk
melakukan
b57a66c2af
1 mengubah file dengan 107 tambahan dan 0 penghapusan
  1. 107 0
      11_vue/5_todolist.html

+ 107 - 0
11_vue/5_todolist.html

@@ -0,0 +1,107 @@
+<!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;
+    }
+    .active{
+      background: red;
+    }
+  </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="searchVal">
+      <button @click="search">搜索</button>
+    </div>
+    <ul>
+      <li v-for="(obj,index) in list"  v-show="obj.isShow" :class="{active:obj.isChecked}">
+        <input type="checkbox" v-model="obj.isChecked">
+        <span>{{obj.name}}</span>
+        <span>{{obj.price}}</span>
+        <span class="close" @click="del(index)">[X]</span>
+      </li>
+    </ul>
+    <div>
+      <button>删除选择</button>
+      <span>总价:{{total()}}</span>
+    </div>
+  </div>
+  <script src="vue.js"></script>
+  <script>
+    new Vue({
+      el: '#app',
+      data: {
+        list: [{
+          name: '苹果',
+          price: 5,
+          isChecked: false,
+          isShow: true
+        }, {
+          name: '香蕉',
+          price: 6,
+          isChecked: false,
+          isShow: true
+        }],
+        name: '',
+        price: '',
+        searchVal:''
+      },
+      methods: {
+        add() {
+          this.list.push({
+            name: this.name,
+            price: this.price,
+            isChecked: false,
+            isShow: true
+          })
+          this.name = ''
+          this.price = ''
+        },
+        total() {
+          var sum = 0;
+          this.list.forEach(function (obj) {
+            if (obj.isChecked) {
+              sum += obj.price * 1
+            }
+          })
+          return sum
+        },
+        search(){
+          this.list.forEach((obj)=>{
+            if(obj.name.includes(this.searchVal)){
+              obj.isShow = true
+            } else{
+              obj.isShow = false
+            }
+          })
+          this.searchVal = ''
+        },
+        del(index){
+          this.list.splice(index,1)
+        }
+      }
+    })
+  </script>
+</body>
+
+</html>