vue3+ts+element-plus 表單el-form取消回車默認(rèn)提交
問題描述:在表單el-form中的el-input中按回車后,頁面會(huì)刷新,url也會(huì)改變,
回車前:
回車后:
相關(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)的回車行為。
擴(kuò)展:
經(jīng)過上述調(diào)整后,在el-input中按回車后不會(huì)默認(rèn)提交表單了,但還需要實(shí)現(xiàn)在el-input中按回車后進(jìn)行查找(相當(dāng)于點(diǎn)擊后面的查找按鈕)
修改后的代碼:
<!-- 使用 @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="請(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鍵、回車鍵、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)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- vue3+ts+element-plus實(shí)際開發(fā)之統(tǒng)一調(diào)用彈窗封裝的詳細(xì)過程
- 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)式布局,可以通過結(jié)合 CSS 媒體查詢、Vue 的動(dòng)態(tài)數(shù)據(jù)綁定、適當(dāng)?shù)牡谌綆臁ostCSS 插件以及正確的視口設(shè)置實(shí)現(xiàn),感興趣的可以了解一下2024-07-07vue鼠標(biāo)hover(懸停)改變background-color移入變色問題
這篇文章主要介紹了vue鼠標(biāo)hover(懸停)改變background-color移入變色問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10解決vue更新路由router-view復(fù)用組件內(nèi)容不刷新的問題
今天小編就為大家分享一篇解決vue更新路由router-view復(fù)用組件內(nèi)容不刷新的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧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