Commit 883b44c48f2fe1d156f1c2484a79bbea9f143477

Authored by 王强
1 parent c619a77f

购好物,搜索,iOS搜索键盘联动Bug处理~

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" ref="searchInput" :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" autofocus :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>
... ... @@ -76,7 +76,7 @@
76 76 confirm(keyword, e) {
77 77  
78 78 // 判断按下的按键是不是回车(确认)
79   - if ((keyword && e.keyCode === 13) || (!keyword && e.keyCode === 8)) {
  79 + if ((keyword && (e.keyCode === 13 || (typeof e.key === "string" && e.key.toLowerCase() === "enter"))) || (!keyword && (e.keyCode === 8 || (typeof e.key === "string" && e.key.toLowerCase() === "backspace")))) {
80 80  
81 81 // 判断不是空格字符串
82 82 if (keyword.trim()) {
... ... @@ -117,21 +117,38 @@
117 117 }
118 118 }
119 119 },
  120 + directives: {
  121 +     focus: {
  122 +         inserted: (el, {value}) => {
  123 +
  124 + // 判断值是否为true
  125 +             if (value) {
  126 +                 el.focus();
  127 +             }
  128 +         }
  129 +     }
  130 + },
120 131 mounted() {
121 132  
122 133 // 合并参数对象
123 134 Object.assign(this.defaultSearchs, this.searchs);
124 135  
125 136 // 延时执行
126   - setTimeout(() => {
  137 + // setTimeout(() => {
127 138  
128   - this.$nextTick(() => {
  139 + // this.$nextTick(() => {
129 140  
130   - if (typeof this.$refs === 'object' && typeof this.$refs.searchInput === 'object') {
131   - this.$refs.searchInput.focus();
132   - }
133   - });
134   - }, 1000);
  141 + // if (typeof this.$refs === 'object' && typeof this.$refs.searchInput === 'object') {
  142 +
  143 +
  144 +
  145 + // console.log(this.$refs);
  146 +
  147 +
  148 + // this.$refs.searchInput.focus();
  149 + // }
  150 + // });
  151 + // }, 1000);
135 152 }
136 153 }
137 154 </script>
... ...