zoukankan      html  css  js  c++  java
  • vue组件绑定原生事件

     1 <!DOCTYPE html>
     2 <html>
     3     <head>
     4         <meta charset="UTF-8">
     5         <title>vue</title>
     6     </head>
     7     <body>
     8         <div id="app">
     9             <child @click="handleClick"></child><!--这个click为自定义事件-->
    10         </div>        
    11         
    12         <!-- 开发环境版本,包含了用帮助的命令行警activeOne告 -->
    13         <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    14         <script>
    15             Vue.component('child', {                
    16                 template: '<div @click="handleChildClick">child</div>',
    17                 methods: {
    18                     handleChildClick: function() {
    19                         alert('child click');
    20                         this.$emit('click');//绑定一个自定义click事件
    21                     }
    22                 }
    23             })
    24             var app = new Vue({
    25                 el: '#app',
    26                 methods: {
    27                     //父组件接收到绑定的handleClick事件
    28                     handleClick: function() {
    29                         alert('click');
    30                     }
    31                 }
    32             })
    33             //整体先弹出child click,再弹出click
    34         </script>
    35     </body>
    36 </html>
    添加.native表示绑定原生事件
     1 <!DOCTYPE html>
     2 <html>
     3     <head>
     4         <meta charset="UTF-8">
     5         <title>vue</title>
     6     </head>
     7     <body>
     8         <div id="app">
     9             <child @click.native="handleClick"></child><!--添加.native表示绑定原生事件-->
    10         </div>        
    11         
    12         <!-- 开发环境版本,包含了用帮助的命令行警activeOne告 -->
    13         <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    14         <script>
    15             Vue.component('child', {                
    16                 template: '<div>child</div>',                
    17             })
    18             var app = new Vue({
    19                 el: '#app',
    20                 methods: {
    21                     handleClick: function(){
    22                         alert('click')
    23                     }
    24                 }
    25             })
    26         //弹出click
    27         </script>
    28     </body>
    29 </html>
  • 相关阅读:
    P1144 最短路计数 题解 最短路应用题
    C++高精度加减乘除模板
    HDU3746 Teacher YYF 题解 KMP算法
    POJ3080 Blue Jeans 题解 KMP算法
    POJ2185 Milking Grid 题解 KMP算法
    POJ2752 Seek the Name, Seek the Fame 题解 KMP算法
    POJ2406 Power Strings 题解 KMP算法
    HDU2087 剪花布条 题解 KMP算法
    eclipse创建maven项目(详细)
    maven的作用及优势
  • 原文地址:https://www.cnblogs.com/1032473245jing/p/9032851.html
Copyright © 2011-2022 走看看