首頁  >  問答  >  主體

javascript - Vue鍵盤事件為何要加上native?

<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這裡必須加上 .native 才能生效.

女神的闺蜜爱上我女神的闺蜜爱上我2663 天前830

全部回覆(4)我來回復

  • 天蓬老师

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

    因為你@keyup.enter是寫在一個封裝好的組件上
    如果你寫在一個input上就不需要.native
    至於為什麼,請參考vue文檔

    回覆
    0
  • 三叔

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

    給予元件綁定原生事件所採用的方法

    回覆
    0
  • 阿神

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

    @ 這個東西其實是 v-on 的簡寫,而 v-on 則是 Vue 的事件體系封裝後的 API 介面。

    Vue 的官方文件中指出了,Vue 使用的是一套自己的事件傳遞機制,如 @click 等事件是經過 Vue 封裝的。因此,在一些實際上處理 DOM 原生事件的場合才需要增加額外的識別碼。

    回覆
    0
  • 天蓬老师

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

    沉了沉了....

    回覆
    0
  • 取消回覆