Browse Source

fix:day26

e 1 year ago
parent
commit
d5d1372a98
3 changed files with 105 additions and 31 deletions
  1. 24 31
      day26/3.计算属性.html
  2. 39 0
      day26/4.计算属性.html
  3. 42 0
      day26/5.条件渲染.html

+ 24 - 31
day26/3.计算属性.html

@@ -15,7 +15,7 @@
                 名:<input type="text" v-model="liName">
             </p>
 
-            <p @click="getName()">姓名是: {{myName}}</p>
+            <p>姓名是: {{myName}}</p>
         </div>
         <p>名字是:{{firstName + lastName}}</p>
         <p>我们的名字是:{{ getFullName() }}</p>
@@ -58,49 +58,42 @@
                 myName:{
                     // 走的是getter 实际get方法
                     get(){
-                        console.log(this.newName,'获取1');
-                        console.log(this.liName,'获取2');
                         return this.newName + '-' + this.liName;
                     },
-                    set(value) {
-                        console.log(value,'获取set值');
-                        const arr = value.split('-');
-                        this.newName = arr[1];
-                        this.liName = arr[0];
-                        console.log("set设置")
+                    set() {
+                        this.newName = "天气";
+                        this.liName = "真好";
                     }
                 }
             },
-            watch:{
-                // 初次进入页面 并不监听 发生更改才会开启监听
-                newName(newValue,oldValue) {
-                    this.full = newValue + this.liName; 
-                },
-                liName(newValue,oldValue) {
-                    this.full = this.newName + newValue;
-                },
-                // 如果我们想 初始化页面进行监听 
-                // 补充知识点
-                // newValue: {
-                //     // 开启监听 , 深度监听
-                //     immediate:true,
-                //     deep: true,
-                //     handler() {
-                //     }
-                // }
-            },
+            // watch:{
+            //     // 初次进入页面 并不监听 发生更改才会开启监听
+            //     newName(newValue,oldValue) {
+            //         this.full = newValue + this.liName; 
+            //     },
+            //     liName(newValue,oldValue) {
+            //         this.full = this.newName + newValue;
+            //     },
+            //     // 如果我们想 初始化页面进行监听 
+            //     // 补充知识点
+            //     // newName: {
+            //     //     // 开启监听 , 深度监听
+            //     //     immediate:true,
+            //     //     deep: true,
+            //     //     handler() {
+            //     //     }
+            //     // }
+            // },
             // 自定义的方法
             methods: {
                 getFullName() {
                     // this => Vue实例
                    return this.firstName + this.lastName + this.full;
-                },
-                getName() {
-                    console.log(this.newName);
-                    console.log(this.liName);
                 }
             },
         })
+        // 解决set失效问题
+        vm.myName = '';
     </script>
 </body>
 </html>

+ 39 - 0
day26/4.计算属性.html

@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+</head>
+<body>
+    <div id="app">
+        <input type="text" v-model="firstName">
+        <input type="text" v-model="lastName">
+        {{fullName}}
+    </div>
+    <script src="./vue.js"></script>
+    <script>
+        var app = new Vue({
+            el:"#app",
+            data:{
+                firstName:'我的',
+                lastName: '名字'
+            },
+            // 当我的值发生变化
+            computed:{
+                fullName:{
+                    get() {
+                        return this.firstName + '-' + this.lastName
+                    },
+                    set(newValue) {
+                        console.log(newValue,'www');
+                        this.firstName = '我的名字';
+                        this.lastName = '叫显眼包'
+                    }
+                }
+            }
+        })
+        app.fullName = ''
+    </script>
+</body>
+</html>

+ 42 - 0
day26/5.条件渲染.html

@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+</head>
+<body>
+    <div id="app">
+        {{score}}
+        <!-- 
+            条件显示 只有条件满足时 才会执行 v-if
+            只要满足条件就会展示 v-show 
+            v-if和v-show的区别
+            1.当你频繁切换时 使用v-show  条件逻辑性 v-if
+            2.v-if 消耗性能
+            3.v-show 只是单纯的展示隐藏
+         -->
+        <p v-if="score >= 90">优秀</p>
+        <p v-else-if="score>=80">良好</p>
+        <p v-else-if="score>=70">凑合</p>
+        <p v-else-if="score>=60">及格</p>
+        <p v-else>不及格</p>
+        <hr>
+        
+        <p v-show="score >= 90">优秀</p>
+        <p v-show="score>=80">良好</p>
+        <p v-show="score>=70">凑合</p>
+        <p v-show="score>=60">及格</p>
+        <p v-show="score < 60">不及格</p>
+    </div>
+    <script src="./vue.js"></script>
+    <script>
+        var app = new Vue({
+            el:"#app",
+            data:{
+                score: Math.ceil(Math.random() * 100)
+            },
+        })
+    </script>
+</body>
+</html>