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. Span標簽2. css - 求推薦適用于vue2的框架 像bootstrap這種類型的3. docker-machine添加一個已有的docker主機問題4. css - 關于div自適應問題,大家看圖吧,說不清5. 關docker hub上有些鏡像的tag被標記““This image has vulnerabilities””6. SessionNotFoundException:會話ID為null。調用quit()后使用WebDriver嗎?(硒)7. android新手一枚,android使用httclient獲取服務器端數據失敗,但是用java工程運行就可以成功獲取。8. angular.js使用$resource服務把數據存入mongodb的問題。9. java - Collections類里的swap函數,源碼為什么要新定義一個final的List型變量l指向傳入的list?10. python - django如何每次調用標簽的時候都取隨機數據
