zsydgithub преди 1 година
родител
ревизия
ec4e0498e4
променени са 3 файла, в които са добавени 140 реда и са изтрити 0 реда
  1. 42 0
      11_vue/6_set.html
  2. 45 0
      11_vue/7_computed.html
  3. 53 0
      11_vue/8_watch.html

+ 42 - 0
11_vue/6_set.html

@@ -0,0 +1,42 @@
+<!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>
+</head>
+<body>
+  <div id="app">
+    <button @click="change()">修改</button>
+    <ul>
+      <li v-for="(val,index) in arr">
+        {{val}}
+        {{index}}
+      </li>
+    </ul>
+  </div>
+  <script src="vue.js"></script>
+  <script>
+    new Vue({
+      el: '#app',
+      data:{
+        arr:['a','b','c','d'],
+        person:{
+          name:'zs'
+        }
+      },
+      methods:{
+        change(){
+          console.log(111)
+          // this.arr[0] = 'x'
+          /* Vue中  不能使用数组[索引]修改数组   因为页面不更新 */
+          /* Vue 要大写 */
+          /* Vue.set(data数据,修改值的索引,修改的参数) */
+          Vue.set(this.person,'name','lisi')
+        }  
+      }
+    })
+  </script>
+</body>
+</html>

+ 45 - 0
11_vue/7_computed.html

@@ -0,0 +1,45 @@
+<!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>
+</head>
+<body>
+  <div id="app">
+    {{msg}}
+    <br>
+    {{msg.split('').reverse().join('')}}
+    <br>
+    方法: {{newMsg1()}}
+    <br>
+    计算属性: {{newMsg2}}
+  </div>
+  <script src="vue.js"></script>
+  <script>
+    new Vue({
+      el:'#app',
+      data:{
+        msg: 'hello word'
+      },
+      methods:{
+        newMsg1(){
+          return this.msg.split('').reverse().join('')
+        }
+      },
+      computed:{
+        //计算属性  依赖其他值去进行计算  缓存  不会重新计算  除非依赖的值有变动 
+        /* 
+        Vue中  computed  比较特殊的属性   他的值是根据其他属性计算得出来的
+        computed 可以使用 get或者set方法来实现属性的读取和设置
+        get 获取计算属性的值  set设置计算属性的值
+        */
+        newMsg2: function(){
+          return this.msg.split('').reverse().join('')
+        }
+      }
+    })
+  </script>
+</body>
+</html>

+ 53 - 0
11_vue/8_watch.html

@@ -0,0 +1,53 @@
+<!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>
+</head>
+<body>
+  <div id="app">
+    <button @click="change()">修改</button>
+    <h2>姓:{{firstName}}</h2>
+    <h2>名:{{lastName}}</h2>
+    <h2>姓名:{{fullName}}</h2>
+  </div>
+  <script src="vue.js"></script>
+  <script>
+    new Vue({
+      el:'#app',
+      data:{
+        firstName:'zhang',
+        lastName: 'san'
+      },
+      methods:{
+        change(){
+          this.firstName = 'li'
+        }
+      },
+      computed:{
+        fullName: function(){
+          return this.firstName + this.lastName
+        }
+      },
+      watch:{
+        firstName: function(){
+          console.log(111)
+        },
+        lastName: function(){
+          console.log(222)
+        }
+      }
+    })
+    /* 
+    在Vue中,watch和computed都是用来观察数据变化的
+    他们的作用是不同的 
+    watch是响应数据的变化并进行相应的操作
+    computed是用来计算一些基于响应式数据的数据
+    computed 是带有缓存的  当响应式数据没有变化的时候
+    computed不会重新计算  
+    */
+  </script>
+</body>
+</html>