首先介绍一下是什么意思:

意思就是当你给一个vue组件绑定事件时候,要加上native!如果是普通的html元素!就不需要

<div id = "app">
<my-component @click="i_said"></my-component>
</div> Vue.component('my-component', {
template: "<button>点击我</button>",
}) new Vue({
el:"#app",
methods:{
i_said(){
alert("Hello world");
}
}
})

这样在组件上添加事件是没有效果的,如果是普通的html标签当然没问题比如

<div id = "app">
<button @click="i_said">点击我</button>
</div> new Vue({
el:"#app",
methods:{
i_said(){
alert("Hello world");
}
}
})

这样肯定没问题,

组件上添加自定义事件也没问题比如

<div id = "app">
<my-component @say="i_said"></my-component>
</div> Vue.component("my-component", {
template: "<button @click='greet'>点击我</button>",
methods:{
greet(){
this.$emit("say", "Hello world");
}
}
}) new Vue({
el:"#app",
methods:{
i_said(message){
alert(message)
}
}
})

这样也完全没有问题也直接弹出“Hello world”

但是组件要添加原生事件需要加上.native 才会生效

 <div id = "app">
<my-component @click.native="i_said"></my-component>
</div> Vue.component('my-component', {
template: "<button>点击我</button>",
}) new Vue({
el:"#app",
methods:{
i_said(){
alert("Hello world");
}
}
})

这样就能执行了!

Vue-native绑定原生事件的更多相关文章

  1. vue组件绑定原生事件

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  2. vue怎么给自定义组件绑定原生事件

     下面主要以4个示例Demo演示(示例代码JS引用的Vue CDN),建议小伙伴直接复制示例代码运行查看, 赶时间的小伙伴可直接往下拉,看示例demo4 注:全局或局部注册的组件称为子组件,其中声明的 ...

  3. vuejs给组件绑定原生事件

    给组件绑定事件,该事件是自定义的事件 <div id='root'> <child @click='handleClick'></child> </div&g ...

  4. vue 给组件绑定原生事件

    有时候,你可能想在某个组件的根元素上监听一个原生事件.可以使用 v-on 的修饰符 .native.例如: <my-component v-on:click.native="doThe ...

  5. Vue组件绑定自定义事件

    Vue组件使用v-on绑定自定义事件: 可以分为3步理解: 1.在组件模板中按照正常事件机制绑定事件: template: '<button v-on:click="increment ...

  6. elmentUI组件怎么绑定原生事件

    el-input为例: <el-input id="user-input" type="textarea" placeholder="请换行输入 ...

  7. vue样式绑定、事件监听、表单输入绑定、响应接口

    1.样式绑定 操作元素的 class 列表和内联样式是数据绑定的一个常见需求.因为它们都是属性,所以我们可以用 v-bind 处理它们:只需要通过表达式计算出字符串结果即可.不过,字符串拼接麻烦且易错 ...

  8. Vue样式绑定和事件处理器

    一.样式绑定 class 与 style 是 HTML 元素的属性,用于设置元素的样式,我们可以用 v-bind 来设置样式属性. v-bind 在处理 class 和 style 时, 专门增强了它 ...

  9. Vue样式绑定、事件绑定

    1.样式绑定 1.1class类标签绑定 <p :class="对象"> <p :class="数组"> <p :class=&q ...

随机推荐

  1. 【leetcode】1026. Maximum Difference Between Node and Ancestor

    题目如下: Given the root of a binary tree, find the maximum value V for which there exists different nod ...

  2. IO流之RandomAccessFile和File

    通过学习一些经典案例来复习基础 ------------------------------------------------------------------------------------ ...

  3. QTimer不能同时使用两个,用QTimerEvent (QT)

    最近写程序的时候有个界面想定两个QTimer定时器,不同时间干不同的事: QTimer *timer1 = new QTimer(this); QTimer *timer2 = new QTimer( ...

  4. 英语单词debug

    来源——docker官网首页https://www.docker.com/ 翻译 vt. 调试,排除故障,除错,改正有毛病部分 过去式 debugged 过去分词 debugged 现在分词 debu ...

  5. Activiti插件安装(二)

    Eclipse安装 网络在线安装:1) 打开 Help -> Install New Software. 在如下面板中: 2) 在如下 Install 界面板中,点击 Add 按钮: 配置新装插 ...

  6. PHP 使用 PHPExcel 库生成 Excel 文件

    PHPExcel 是用来操作Office Excel 文档的一个PHP类库,它基于微软的OpenXML标准和PHP语言.可以使用它来读取.写入不同格式的电子表格,如 Excel (BIFF) .xls ...

  7. 【ABAP系列】SAP ABAP基础-录制BDC的MODE定义解析

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP基础-录制BDC ...

  8. Git007--删除文件

    Git--删除文件 本文来自于:https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/ ...

  9. C#后台去除字符串最后一个字符

    string str = "a,b,c,"; int length = str.length; //获取字符串长度 str = str.substring(0,length-1); ...

  10. < 备考CET6 - 作文模板句 - 话题:重要性/做选择 >

    CET6 - 作文模板句 - 重要性/做选择 重要性 开头 Currently, We are entering a brand new era filled with (opportunities  ...