vue3+ts+element-plus 表單el-form取消回車默認(rèn)提交
問題描述:在表單el-form中的el-input中按回車后,頁面會刷新,url也會改變,
回車前:
回車后:
相關(guān)代碼:
解決方法1:在 el-form
上阻止默認(rèn)的 submit
事件,增加 @submit.prevent,在 el-form
上監(jiān)聽 submit
事件,并調(diào)用 event.preventDefault()
來阻止默認(rèn)的提交行為。
解決方法2:在 el-form
上阻止默認(rèn)的 submit
事件,增加 @submit.native.prevent,在 el-form
上監(jiān)聽 submit.native
事件,并調(diào)用 event.preventDefault()
來阻止默認(rèn)的提交行為。
解決方法3:在 el-form
上阻止 keydown 回車事件,增加 @keydown.enter.prevent,在 el-form
上監(jiān)聽 keydown.enter
事件,并調(diào)用 event.preventDefault()
來阻止默認(rèn)的回車行為。
解決方法4:在 指定的 el-input 組件上阻止 keydown 回車事件,增加 @keydown.enter.prevent,在 el-input
上監(jiān)聽 keydown.enter
事件,并調(diào)用 event.preventDefault()
來阻止默認(rèn)的回車行為。
擴展:
經(jīng)過上述調(diào)整后,在el-input中按回車后不會默認(rèn)提交表單了,但還需要實現(xiàn)在el-input中按回車后進(jìn)行查找(相當(dāng)于點擊后面的查找按鈕)
修改后的代碼:
<!-- 使用 @keydown.enter.prevent 或 @submit.prevent 或 @submit.native.prevent 取消回車默認(rèn)提交 --> <el-form inline style="height: 32px;" @keydown.enter.prevent> <el-form-item> <!-- 使用 @keydown.enter="onSearchClick" 按回車進(jìn)行查找 --> <!-- 使用 @keydown.a.enter.b="onSearchClick" 按a鍵、回車鍵、b鍵都可以進(jìn)行查找,注意:= 左邊的內(nèi)容不能使用大寫字母 --> <el-input v-model="name" placeholder="請輸入查找內(nèi)容" clearable @keydown.enter="onSearchClick"> <template #append> <el-button :icon="Search" @click="onSearchClick" /> </template> </el-input> </el-form-item> </el-form>
@keydown.enter="onSearchClick"
@keydown.a.enter.b.c.d……="onSearchClick" 按a鍵、回車鍵、b鍵、c鍵、d鍵都可以進(jìn)行查找,注意:= 左邊的內(nèi)容不能使用大寫字母
到此這篇關(guān)于vue3+ts+element-plus 表單el-form取消回車默認(rèn)提交的文章就介紹到這了,更多相關(guān)vue3+ts+element-plus 表單el-form取消回車內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue 自動檢測手機端響應(yīng)式布局的五種實現(xiàn)
本文主要介紹了vue自動檢測手機端響應(yīng)式布局,可以通過結(jié)合 CSS 媒體查詢、Vue 的動態(tài)數(shù)據(jù)綁定、適當(dāng)?shù)牡谌綆臁ostCSS 插件以及正確的視口設(shè)置實現(xiàn),感興趣的可以了解一下2024-07-07vue鼠標(biāo)hover(懸停)改變background-color移入變色問題
這篇文章主要介紹了vue鼠標(biāo)hover(懸停)改變background-color移入變色問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-10-10解決vue更新路由router-view復(fù)用組件內(nèi)容不刷新的問題
今天小編就為大家分享一篇解決vue更新路由router-view復(fù)用組件內(nèi)容不刷新的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-11-11vue2.0實現(xiàn)列表數(shù)據(jù)增加和刪除
這篇文章主要為大家詳細(xì)介紹了vue2.0實現(xiàn)列表數(shù)據(jù)增加和刪除,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-06-06