zsydgithub 1 anno fa
parent
commit
3c867635b4
2 ha cambiato i file con 127 aggiunte e 0 eliminazioni
  1. 68 0
      Vue/15_生命周期.html
  2. 59 0
      Vue/16_component.html

+ 68 - 0
Vue/15_生命周期.html

@@ -0,0 +1,68 @@
+<!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">
+    {{count}}
+    <button @click="add()">+1</button>
+    <button @click="des()">销毁</button>
+  </div>
+  <script src="./vue.js"></script>
+  <script>
+    var app = new Vue({
+      el: '#app',
+      data: {
+        count: 1
+      },
+      methods:{
+        add(){
+          this.count ++
+        },
+        des(){
+          this.$destroy()
+        }
+      },
+      //组件实例刚刚创建之前  属性计算之前
+      beforeCreate() {
+        console.log('beforeCreate', this.$data, this.$el)
+      },
+      //组件实例刚刚创建完成  属性绑定 dom未生成 el不存在
+      created() {
+        console.log('created',this.$data,this.$el)
+      },
+      //挂载之前
+      beforeMount(){
+        console.log('beforeMount',this.$data,this.$el)
+      },
+      //挂载之后
+      mounted(){
+        console.log('mounted',this.$data,this.$el)
+      },
+      //更新之前
+      beforeUpdate(){
+        console.log('beforeUpdate',this.$data,this.$el)
+      },
+      //更新之后
+      updated(){
+        console.log('updated',this.$data,this.$el)
+      },
+      //销毁之前
+      beforeDestroy(){
+        console.log('beforeDestroy',this.$data,this.$el)
+      },
+      destroyed(){
+        console.log('destroyed',this.$data,this.$el)
+      }
+      
+    })
+  </script>
+</body>
+
+</html>

+ 59 - 0
Vue/16_component.html

@@ -0,0 +1,59 @@
+<!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">
+    <my-com name="zhangsan" age="18">
+      <ul>
+        <li>1</li>
+        <li>2</li>
+        <li>3</li>
+      </ul>
+    </my-com>
+    <my-coms></my-coms>
+  </div>
+  <div id="app1">
+    <my-com></my-com>
+  </div>
+  <template id="temp1">
+    <div>
+      <p>{{name}}</p>
+      1111
+      <p>{{age}}</p>
+      <slot></slot>
+      <h2>我是temp1</h2>
+      <h2>我是模板</h2>
+    </div>
+  </template>
+  <script src="./vue.js"></script>
+  <script>
+    //template 模板里面  要有一个最底层的div去嵌套
+    Vue.component('my-coms', {
+      template: '<h2>hahahahhaha</h2>'
+    })
+    new Vue({
+      el: "#app",
+      data: {
+        msg: 1
+      },
+      components: {
+        'my-com': {
+          template: '#temp1',
+          props: ['name', 'age']
+        }
+      }
+    })
+    new Vue({
+      el: '#app1'
+    })
+  </script>
+</body>
+
+</html>