fengchuanyu 3 months ago
parent
commit
9787b27af3

+ 26 - 0
11_Vue基础/3_v-if.html

@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+    <script src="./js/vue.js"></script>
+</head>
+<body>
+    <div id="app">
+        <!-- <h1 v-if="num > 10">当前num大于10</h1>
+        <h1 v-if="num < 10">当前num小于10</h1> -->
+        <h1 v-if="num>10">num 大于 10</h1>
+        <h1 v-else-if="num<10">num 小于 10</h1>
+        <h1 v-else>num 等于 10</h1>
+    </div>
+    <script>
+        let app = new Vue({
+            el: '#app',
+            data:{
+                num:10
+            }
+        })
+    </script>
+</body>
+</html>

+ 23 - 0
11_Vue基础/4_v-show.html

@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+    <script src="./js/vue.js"></script>
+</head>
+<body>
+    <div id="app">
+        <h1 v-show="num>0">显示内容</h1>
+    </div>
+    <script>
+        let app = new Vue({
+            el:"#app",
+            data:{
+                isShow:false,
+                num:-1
+            }
+        })
+    </script>
+</body>
+</html>

+ 73 - 0
11_Vue基础/5_v-on绑定事件.html

@@ -0,0 +1,73 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+    <script src="./js/vue.js"></script>
+    <style>
+        .div1{
+            width: 200px;
+            height: 200px;
+            background-color: blue;
+        }
+        .div2{
+            width: 100px;
+            height: 100px;
+            background-color: red;
+        }
+        .div3{
+            width: 100px;
+            height: 100px;
+            background-color: green;
+        }
+    </style>
+</head>
+<body>
+    <div id="app">
+        <!-- <button v-on:click="clickFun">按钮</button> -->
+        <!-- <button v-on:click="clickFun('hello')">按钮</button> -->
+         
+        <div v-on:click="div1Click" class="div1">
+            <!-- 在vue中获取事件对象使用 $event -->
+            <!-- <div v-on:click="div2Click($event)" class="div2"></div> -->
+
+            <div v-on:click.stop="div2Click($event)" class="div2"></div>
+         </div>
+
+         <!-- <div class="div3" v-on:contextmenu="showMenu($event)"></div> -->
+         <div class="div3" v-on:contextmenu.prevent="showMenu"></div>
+
+         <button @click="click3Fun">简写v-on事件</button>
+
+    </div>
+    <script>
+        let app = new Vue({
+            el:"#app",
+            methods: { //放置方法函数
+                clickFun:function(val){
+                    console.log(val);
+                },
+                div1Click:function(){
+                    console.log("div1被点击了");
+                },
+                div2Click:function(e){
+                    // console.log(e);
+                    // // 用事件对象阻止冒泡
+                    // e.stopPropagation();
+                    console.log("div2被点击了");
+                },
+                showMenu:function(e){
+                    // 用事件对象阻止默认行为
+                    // e.preventDefault();
+                    console.log("右键菜单")
+                    
+                },
+                click3Fun:function(){
+                    console.log("v-on简写");
+                }
+            },
+        })
+    </script>
+</body>
+</html>

+ 28 - 0
11_Vue基础/6_修改数据.html

@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+    <script src="./js/vue.js"></script>
+</head>
+<body>
+    <div id="app">
+        <h1>{{str}}</h1>
+        <button @click="changeStr">按钮</button>
+    </div>
+    <script>
+        let app = new Vue({
+            el: '#app',
+            data:{
+                str:"hello world"
+            },
+            methods: {
+                changeStr:function(){
+                    this.str = "你好世界";
+                }
+            }
+        })
+    </script>
+</body>
+</html>