vue中使用element ui的input框?qū)崿F(xiàn)模糊搜索的輸入框
說(shuō)不多說(shuō)直接貼代碼,在template里面:
<el-autocomplete
class="inline-input"
v-model="disease"
:fetch-suggestions="querySearch"
placeholder="請(qǐng)輸入疾病名稱"
:trigger-on-focus="false" //這個(gè)改為true就是激活即列出輸入建議
@select="handleSelect"
@keyup.enter.native="search"
></el-autocomplete>在data里面:
data () {
return {
diseaseList: [], //這個(gè)值是需要匹配的值
disease: '' //這個(gè)值是用戶正在輸入的值
}
}在mounted里面
這里主要是給diseaseList賦值,這個(gè)準(zhǔn)備用來(lái)匹配用戶輸入的值disease是否與diseaseList相同。
mounted () {
getDiseaseMainSetting().then(res => {
if (res.code === 200) {
res.data.forEach(item => {
this.diseaseList.push({
id: item.icdMainId,
value: item.icdMainName
})
})
}
})
},在methods里面
/* fetch-suggestions 是一個(gè)返回輸入建議的方法屬性,在該方法中你可以在輸入建議數(shù)據(jù)準(zhǔn)備好時(shí)通過(guò) cb(data) 返回到 autocomplete 組件中. */
querySearch (queryString, cb) {
const diseaseList = this.diseaseList
const results = queryString
? diseaseList.filter(this.createFilter(queryString))
: diseaseList
// 調(diào)用 callback 返回建議列表的數(shù)據(jù)
cb(results)
},
createFilter (queryString) {
return disease => {
return (
disease.value.toLowerCase().indexOf(queryString.toLowerCase()) !== -1 // 改為===0 就是篩選的數(shù)據(jù)只是首字匹配的列表項(xiàng),需要包含輸入字的所有列表項(xiàng)改為!==-1
)
}
},
/* 跳轉(zhuǎn)并傳值 */
handleSelect (item) {
if (this.$route.path === '/clinicalAnalysis') {
this.$router.push({
path: '/effectAnalysis',
query: { keyword: this.disease, id: item.id }
})
}
},
handleIconClick (ev) {
console.log(ev)
}
}如果需要加一個(gè)點(diǎn)擊確認(rèn)的按鈕,方法類似,代碼如下:
<el-button type="primary" @click="search">搜索</el-button>
方法如下:
search () {
if (!this.disease) {
this.$message.warning('請(qǐng)輸入您要搜索疾病的名稱')
return
}
/* 跳轉(zhuǎn)并傳值 */
if (this.$route.path === '/clinicalAnalysis') {
let diseaseMess = []
this.diseaseList.forEach((item, index) => {
if (this.disease === item.value) {
diseaseMess.push(item.value)
this.$router.push({
path: '/effectAnalysis',
query: { keyword: this.disease, id: item.id }
})
}
})
// 判斷一下,如果該長(zhǎng)度為0的話,那就證明輸入的內(nèi)容和列表的內(nèi)容不一樣。
if (diseaseMess.length === 0) {
this.$message.warning('未配置“' + this.disease + '”該病種')
}
} else {
let keywords = []
let errorMess = []
this.diseaseList.forEach(item => {
if (this.disease === item.value) {
errorMess.push(item.value)
keywords.push({
name: item.value,
id: item.id
})
}
})
if (errorMess.length === 0) {
this.$message.warning('未配置“' + this.disease + '”該病種')
}
this.$emit('keywords', keywords)
}
},部分解釋


效果如下:



到此這篇關(guān)于vue中使用element ui的input框做一個(gè)帶模糊搜索的輸入框的文章就介紹到這了,更多相關(guān)vue element ui輸入框內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Element-ui table中過(guò)濾條件變更表格內(nèi)容的方法
下面小編就為大家分享一篇Element-ui table中過(guò)濾條件變更表格內(nèi)容的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-03-03
Vue使用Echarts實(shí)現(xiàn)立體柱狀圖
這篇文章主要為大家詳細(xì)介紹了Vue使用Echarts實(shí)現(xiàn)立體柱狀圖,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09
Vue使用Vuex一步步封裝并使用store全過(guò)程
這篇文章主要介紹了Vue使用Vuex一步步封裝并使用store全過(guò)程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-01-01
vue判斷內(nèi)容是否滑動(dòng)到底部的三種方式
這篇文章主要介紹了vue判斷內(nèi)容是否滑動(dòng)到底部的三種方式,文中通過(guò)代碼示例給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下2024-04-04
深入探討Vue3組件中的圖片懶加載的實(shí)現(xiàn)原理與應(yīng)用
本文將深入探討?Vue3?中圖片懶加載的實(shí)現(xiàn)原理,從底層的?IntersectionObserver?到高級(jí)的?LQIP?漸進(jìn)式加載,最終手寫(xiě)一個(gè)完整的圖片懶加載指令和預(yù)加載組件,感興趣的小伙伴可以了解下2026-03-03
vue2+elementui的el-table固定列會(huì)遮住橫向滾動(dòng)條及錯(cuò)位問(wèn)題解決方案
這篇文章主要介紹了vue2+elementui的el-table固定列會(huì)遮住橫向滾動(dòng)條及錯(cuò)位問(wèn)題解決方案,主要解決固定列錯(cuò)位后, 接下來(lái)就是把固定列往上提滾動(dòng)條的高度就不會(huì)影響了,需要的朋友可以參考下2024-01-01
京東 Vue3 組件庫(kù)支持小程序開(kāi)發(fā)的詳細(xì)流程
這篇文章主要介紹了京東 Vue3 組件庫(kù)支持小程序開(kāi)發(fā)的詳細(xì)流程,通過(guò)引入NutUI,即可在項(xiàng)目中使用,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-06-06

