Commit f379733efbccad40ed1d7408faa2de63ee6defc2
1 parent
ac3d3dbd
优选库——搜索,屏蔽搜索空格~
Showing
2 changed files
with
20 additions
and
2 deletions
src/components/searchCom/searchCom.less
src/components/searchCom/searchCom.vue
| ... | ... | @@ -9,7 +9,7 @@ |
| 9 | 9 | </div> |
| 10 | 10 | <div class="line"></div> |
| 11 | 11 | <div class="input-box"> |
| 12 | - <input type="search" :placeholder="defaultSearchs.pl" :maxlength="defaultSearchs.maxlength" v-model="defaultSearchs.keyword" class="keyword" @keyup="confirm(defaultSearchs.keyword, $event)" @blur="onBlur" /> | |
| 12 | + <input type="search" ref="searchInput" :placeholder="defaultSearchs.pl" :maxlength="defaultSearchs.maxlength" v-model="defaultSearchs.keyword" class="keyword" @keyup="confirm(defaultSearchs.keyword, $event)" @blur="onBlur" /> | |
| 13 | 13 | </div> |
| 14 | 14 | </form> |
| 15 | 15 | </div> |
| ... | ... | @@ -67,7 +67,13 @@ |
| 67 | 67 | |
| 68 | 68 | // 判断按下的按键是不是回车(确认) |
| 69 | 69 | if ((keyword && e.keyCode === 13) || (!keyword && e.keyCode === 8)) { |
| 70 | - this.$emit("confirm", keyword); | |
| 70 | + | |
| 71 | + // 判断不是空格字符串 | |
| 72 | + if (keyword.trim()) { | |
| 73 | + this.$emit("confirm", keyword); | |
| 74 | + } else { | |
| 75 | + this.setKeyword(''); | |
| 76 | + } | |
| 71 | 77 | } |
| 72 | 78 | }, |
| 73 | 79 | |
| ... | ... | @@ -105,6 +111,17 @@ |
| 105 | 111 | |
| 106 | 112 | // 合并参数对象 |
| 107 | 113 | Object.assign(this.defaultSearchs, this.searchs); |
| 114 | + | |
| 115 | + // 延时执行 | |
| 116 | + setTimeout(() => { | |
| 117 | + | |
| 118 | + this.$nextTick(() => { | |
| 119 | + | |
| 120 | + if (typeof this.$refs === 'object' && typeof this.$refs.searchInput === 'object') { | |
| 121 | + this.$refs.searchInput.focus(); | |
| 122 | + } | |
| 123 | + }); | |
| 124 | + }, 1000); | |
| 108 | 125 | } |
| 109 | 126 | } |
| 110 | 127 | </script> | ... | ... |