Vue2.x通用條件搜索組件的封裝及應用詳解
本文實例為大家分享了Vue2.x通用條件搜索組件的封裝及應用,供大家參考,具體內(nèi)容如下
效果
組件源碼
<template> <div class="search"> <el-select v-model="type" @change="changeType" class="select"> <el-option v-for="item in selectItems" :key="item.value" :lable="item.label" :value="item.value"> </el-option> </el-select> <div class='search-input'> <el-input :placeholder="placeholderDes" v-model="searchValue"></el-input> </div> <el-button icon="el-icon-search" @click="search"></el-button> </div> </template> <script> export default { data () { return { searchValue: '', type: '' } }, created () { this.type = this.initType }, props: { selectItems: { type: Array, require: true }, placeholderDes: { type: String, require: true }, initType: { type: String, require: true } }, methods: { changeType (newType) { this.$emit('changeType', newType) }, search () { this.$emit('searchOk', this.searchValue) } } } </script> <style lang="less" scoped> .search { display: flex; .el-select { width: 90px; height: 40px; box-sizing: border-box; border-right: none; border-radius: 0; background-color: #DDF0FE; border: 1px solid #40b0ff; } .search-input { width: 216px; height: 40px; border: 1px solid #40b0ff; border-left: none; box-sizing: border-box; font-family: 'MicrosoftYaHei'; font-size: 14px; color: #909399; border-radius: 0; } .el-button { width: 44px; height: 40px; padding: 0; border: 1px solid #40b0ff; border-radius: 0; color: #fff; background: #40b0ff; &:hover { background: #10b0ff } } } </style>
父組件中的引用
<template> <div class="test"> <v-search :initType="initType" :selectItems="selectItems" :placeholderDes="placeholderDes" @changeType="changeType" @searchOk="searchOk"></v-search> </div> </template> <script> import VSearch from '@/components/Common/ZLGComponents/XGQTest/Search/Search' export default { data () { return { selectItems: [], selectStatus: 'devname', initType: '', placeholderDes: '請輸入要搜索的測試名稱' } }, created () { this.setSelectItems() this.setInitType() }, methods: { setSelectItems () { this.selectItems = [{ value: '測試名', label: '測試名' }, { value: '測試ID', label: '測試ID' }] }, changeType (newType) { if (newType === '測試名') { this.placeholderDes = '請輸入要搜索的測試名稱' this.selectStatus = 'name' } else if (newType === '測試ID') { this.placeholderDes = '請輸入要搜索的測試ID' this.selectStatus = 'id' } }, searchOk (value) { console.log(this.selectStatus) console.log(value) // 調(diào)用你的搜索接口,搜索條件為搜索的類型 + 搜索值 // yourSearch (this.selectStatus, value) }, setInitType () { this.initType = '測試名' } }, components: { VSearch } } </script> <style lang="less" scoped> </style>
組件基于element-UI的二次封裝,適合用于使用element的項目,子組件父組件demo完整源碼如上所示,有疑問建議研究一下源碼,也歡迎留言交流。
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
- Vue2與Vue3兄弟組件通訊bus的區(qū)別及用法
- vue2.* element tabs tab-pane 動態(tài)加載組件操作
- vue2.0 獲取從http接口中獲取數(shù)據(jù),組件開發(fā),路由配置方式
- vue2.0+SVG實現(xiàn)音樂播放圓形進度條組件
- vue2 拖動排序 vuedraggable組件的實現(xiàn)
- Vue2.x通用編輯組件的封裝及應用詳解
- Vue2.0實現(xiàn)組件之間數(shù)據(jù)交互和通信操作示例
- 詳解基于Vue2.0實現(xiàn)的移動端彈窗(Alert, Confirm, Toast)組件
- 在vue2.0中引用element-ui組件庫的方法
- Vue2 的12種組件通訊
相關文章
vue-router之nuxt動態(tài)路由設置的兩種方法小結(jié)
今天小編就為大家分享一篇vue-router之nuxt動態(tài)路由設置的兩種方法小結(jié),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-09-09如何解決this.$refs.form.validate()不執(zhí)行的問題
這篇文章主要介紹了如何解決this.$refs.form.validate()不執(zhí)行的問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-09-09從0搭建Vue3組件庫如何使用?glup?打包組件庫并實現(xiàn)按需加載
這篇文章主要介紹了從0搭建Vue3組件庫如何使用?glup?打包組件庫并實現(xiàn)按需加載,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-03-03elementUI組件中el-date-picker限制時間范圍精確到小時的方法
現(xiàn)在需要做一個時間選擇器,可以根據(jù)小時(同時選天和小時)和天?和月,節(jié)假日等類型控制日歷的選擇樣式,下面這篇文章主要給大家介紹了關于elementUI組件中el-date-picker限制時間范圍精確到小時的相關資料,需要的朋友可以參考下2023-04-04vuex實現(xiàn)數(shù)據(jù)持久化的兩種方案
這兩天在做vue項目存儲個人信息的時候,遇到了頁面刷新后個人信息數(shù)據(jù)丟失的問題,在查閱資料后,我得出兩種解決數(shù)據(jù)丟失,使用數(shù)據(jù)持久化的方法,感興趣的小伙伴跟著小編一起來看看吧2023-08-08vue使用高德地圖根據(jù)坐標定位點的實現(xiàn)代碼
這篇文章主要介紹了vue使用高德地圖根據(jù)坐標定位點的實現(xiàn)代碼,代碼簡單易懂,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2019-08-08