Heim  >  Fragen und Antworten  >  Hauptteil

javascript - Warum sollten Vue-Tastaturereignisse zu Native hinzugefügt werden?

<template>

<el-form :model="ruleForm2" :rules="rules2" ref="ruleForm2" label-position="left" label-width="0px"
         class="demo-ruleForm login-container" >
    <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" style="width:100%;"  @click.native.prevent="handleSubmit2" :loading="logining" >登录
        </el-button>
    </el-form-item>
</el-form>

</template>

@keyup.enter muss hier hinzugefügt werden, damit es wirksam wird

女神的闺蜜爱上我女神的闺蜜爱上我2663 Tage vor828

Antworte allen(4)Ich werde antworten

  • 天蓬老师

    天蓬老师2017-07-05 11:03:27

    因为你@keyup.enter是写在一个封装好的组件上
    如果你写在一个input上就不需要.native
    至于为什么,请参考vue文档

    Antwort
    0
  • 三叔

    三叔2017-07-05 11:03:27

    给组件绑定原生事件采用的方法

    Antwort
    0
  • 阿神

    阿神2017-07-05 11:03:27

    @ 这个东西实际上是 v-on 的简写,而 v-on 则是对 Vue 的事件体系封装后的 API 接口。

    Vue 的官方文档中指出了,Vue 使用的是一套自己的事件传递机制,如 @click 等事件是经过 Vue 封装的。因此,在一些实际上处理 DOM 原生事件的场合才需要添加额外的标识符。

    Antwort
    0
  • 天蓬老师

    天蓬老师2017-07-05 11:03:27

    沉了沉了....

    Antwort
    0
  • StornierenAntwort