javascript - Vue鍵盤事件為何要加上native?
女神的闺蜜爱上我
女神的闺蜜爱上我 2017-07-05 11:01:27
0
4
814

<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 才能生效.

女神的闺蜜爱上我
女神的闺蜜爱上我

全部回覆(4)
Peter_Zhu

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

三叔

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

阿神

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

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

Peter_Zhu

沉了沉了....

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!