vue3+ts+element-plus 表單el-form取消回車(chē)默認(rèn)提交
問(wèn)題描述:在表單el-form中的el-input中按回車(chē)后,頁(yè)面會(huì)刷新,url也會(huì)改變,
回車(chē)前:
回車(chē)后:
相關(guān)代碼:
解決方法1:在 el-form
上阻止默認(rèn)的 submit
事件,增加 @submit.prevent,在 el-form
上監(jiān)聽(tīng) submit
事件,并調(diào)用 event.preventDefault()
來(lái)阻止默認(rèn)的提交行為。
解決方法2:在 el-form
上阻止默認(rèn)的 submit
事件,增加 @submit.native.prevent,在 el-form
上監(jiān)聽(tīng) submit.native
事件,并調(diào)用 event.preventDefault()
來(lái)阻止默認(rèn)的提交行為。
解決方法3:在 el-form
上阻止 keydown 回車(chē)事件,增加 @keydown.enter.prevent,在 el-form
上監(jiān)聽(tīng) keydown.enter
事件,并調(diào)用 event.preventDefault()
來(lái)阻止默認(rèn)的回車(chē)行為。
解決方法4:在 指定的 el-input 組件上阻止 keydown 回車(chē)事件,增加 @keydown.enter.prevent,在 el-input
上監(jiān)聽(tīng) keydown.enter
事件,并調(diào)用 event.preventDefault()
來(lái)阻止默認(rèn)的回車(chē)行為。
擴(kuò)展:
經(jīng)過(guò)上述調(diào)整后,在el-input中按回車(chē)后不會(huì)默認(rèn)提交表單了,但還需要實(shí)現(xiàn)在el-input中按回車(chē)后進(jìn)行查找(相當(dāng)于點(diǎn)擊后面的查找按鈕)
修改后的代碼:
<!-- 使用 @keydown.enter.prevent 或 @submit.prevent 或 @submit.native.prevent 取消回車(chē)默認(rèn)提交 --> <el-form inline style="height: 32px;" @keydown.enter.prevent> <el-form-item> <!-- 使用 @keydown.enter="onSearchClick" 按回車(chē)進(jìn)行查找 --> <!-- 使用 @keydown.a.enter.b="onSearchClick" 按a鍵、回車(chē)鍵、b鍵都可以進(jìn)行查找,注意:= 左邊的內(nèi)容不能使用大寫(xiě)字母 --> <el-input v-model="name" placeholder="請(qǐng)輸入查找內(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鍵、回車(chē)鍵、b鍵、c鍵、d鍵都可以進(jìn)行查找,注意:= 左邊的內(nèi)容不能使用大寫(xiě)字母
到此這篇關(guān)于vue3+ts+element-plus 表單el-form取消回車(chē)默認(rèn)提交的文章就介紹到這了,更多相關(guān)vue3+ts+element-plus 表單el-form取消回車(chē)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- vue3+ts+element-plus實(shí)際開(kāi)發(fā)之統(tǒng)一調(diào)用彈窗封裝的詳細(xì)過(guò)程
- vue3+vite+TS中使用element-plus按需引入ElLoading、ElMessage樣式失效解決
- vue3使用element-plus中el-table組件報(bào)錯(cuò)關(guān)鍵字'emitsOptions'與'insertBefore'分析
- Vue3+Vite+TS實(shí)現(xiàn)二次封裝element-plus業(yè)務(wù)組件sfasga
- vite+vue3.0+ts+element-plus快速搭建項(xiàng)目的實(shí)現(xiàn)
相關(guān)文章
vue 自動(dòng)檢測(cè)手機(jī)端響應(yīng)式布局的五種實(shí)現(xiàn)
本文主要介紹了vue自動(dòng)檢測(cè)手機(jī)端響應(yīng)式布局,可以通過(guò)結(jié)合 CSS 媒體查詢(xún)、Vue 的動(dòng)態(tài)數(shù)據(jù)綁定、適當(dāng)?shù)牡谌綆?kù)、PostCSS 插件以及正確的視口設(shè)置實(shí)現(xiàn),感興趣的可以了解一下2024-07-07Vuex?Action的?{?commit?}的寫(xiě)法教程
實(shí)踐中,我們會(huì)經(jīng)常用到?ES2015?的參數(shù)解構(gòu)來(lái)簡(jiǎn)化代碼(特別是我們需要調(diào)用commit很多次的時(shí)候,{commit}?寫(xiě)法是解構(gòu)后得到的,這篇文章主要介紹了Vuex?Action的{?commit?}的寫(xiě)法,需要的朋友可以參考下2023-10-10vue鼠標(biāo)hover(懸停)改變background-color移入變色問(wèn)題
這篇文章主要介紹了vue鼠標(biāo)hover(懸停)改變background-color移入變色問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10解決vue更新路由router-view復(fù)用組件內(nèi)容不刷新的問(wèn)題
今天小編就為大家分享一篇解決vue更新路由router-view復(fù)用組件內(nèi)容不刷新的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-11-11簡(jiǎn)單實(shí)現(xiàn)一個(gè)vue公式編輯器組件demo
這篇文章主要介紹了輕松實(shí)現(xiàn)一個(gè)簡(jiǎn)單的vue公式編輯器組件示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2024-01-01vue2.0實(shí)現(xiàn)列表數(shù)據(jù)增加和刪除
這篇文章主要為大家詳細(xì)介紹了vue2.0實(shí)現(xiàn)列表數(shù)據(jù)增加和刪除,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-06-06