12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <!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>
- .box1{
- width: 400px;
- height: 400px;
- background-color: red;
- }
- .box2{
- width: 200px;
- height: 200px;
- background-color: blue;
- }
- </style>
- </head>
- <body>
- <div id="app">
- <!-- v-on 事件绑定 v-on:事件类型=事件处理函数-->
- <button v-on:click="btnFun">按钮</button>
- <div class="box1" v-on:click="box1Fun">
- <!-- v-on 修饰符 .stop阻止事件冒泡 -->
- <div class="box2" v-on:click.stop="box2Fun"></div>
- </div>
- <!-- v-on 修饰符 .prevent阻止默认行为 -->
- <div class="box2" v-on:contextmenu.prevent="rightClick"></div>
- </div>
- <script>
- new Vue({
- el:"#app",
- methods:{
- btnFun(){
- console.log("hello world");
- },
- box1Fun(){
- console.log("box1")
- },
- box2Fun(){
- console.log("box2")
- },
- rightClick(){
- console.log("右键点击")
- }
- }
- })
- </script>
- </body>
- </html>
|