javascript - Vue键盘事件为何要加上native?
问题描述
<template>
<el-form :model='ruleForm2' :rules='rules2' ref='ruleForm2' label-position='left' label- > <h3 class='title'>系统登录</h3> <el-form-item prop='account'><el-input type='text' v-model='ruleForm2.account' auto-complete='off' placeholder='账号'></el-input> </el-form-item> <el-form-item prop='password'><el-input type='password' v-model='ruleForm2.password' auto-complete='off' placeholder='密码' @keyup.enter.native='handleSubmit2'></el-input> </el-form-item> <el-form-item style='width:100%;'><el-button type='primary' @click.native.prevent='handleSubmit2' :loading='logining' >登录</el-button> </el-form-item></el-form>
</template>
@keyup.enter这里必须加上 .native 才能生效.
问题解答
回答1:因为你@keyup.enter是写在一个封装好的组件上 如果你写在一个input上就不需要.native 至于为什么,请参考vue文档
回答2:给组件绑定原生事件采用的方法
回答3:@ 这个东西实际上是 v-on 的简写,而 v-on 则是对 Vue 的事件体系封装后的 API 接口。
Vue 的官方文档中指出了,Vue 使用的是一套自己的事件传递机制,如 @click 等事件是经过 Vue 封装的。因此,在一些实际上处理 DOM 原生事件的场合才需要添加额外的标识符。
回答4:沉了沉了....
相关文章:
1. 关于docker下的nginx压力测试2. mysql - 仅仅只是把单引号与反斜杠转义不用prepare statement能否避免sql注入?3. 如何解决Centos下Docker服务启动无响应,且输入docker命令无响应?4. docker api 开发的端口怎么获取?5. docker 下面创建的IMAGE 他们的 ID 一样?这个是怎么回事????6. docker网络端口映射,没有方便点的操作方法么?7. html5 - 请问一下写H5的时候 你们都是兼容那些手机8. docker-machine添加一个已有的docker主机问题9. sublime-text - sublime text 3中编译python(sublimeREPL),如何仅运行单行/选定部分10. python - 字符串里的u’u00a1’怎么打印成中文

网公网安备