900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > 关于手机端点击搜索按钮跳转到搜索页面 搜索框自动聚焦并且唤起键盘

关于手机端点击搜索按钮跳转到搜索页面 搜索框自动聚焦并且唤起键盘

时间:2019-11-12 20:46:13

相关推荐

关于手机端点击搜索按钮跳转到搜索页面 搜索框自动聚焦并且唤起键盘

index页面:

<div @click="gotoSearch()">// 首页取一个和搜索页面搜索框一样的class名<input class="van-field__control" /><img src="@/asset/images/你的搜索图标地址" /></div><export default{methods:{gotoSearch(){let inp = document.getElementsByClassName('van-field__control')[0];inp.focus();this.$router.push({name:'searchList',})}}}<style>.van-field__control{width:0;height:0;}</style>

以上是index页面,就是点击这里的搜索图标跳转到搜索页面的,下面是搜索页面的代码~

<van-search @cancel="onCancel"@search="onSearch"@focus="onFocus"@blur="onBlur"v-model="keyword"show-actionplaceholder="请输入关键词"ref="searchInput" />mounted(){this.$refs.searchInput.focus();}async activated(){let inp = document.getElementsByClassName('van-field__control')[0];inp.focus();}

以上代码,可兼容IOS和安卓,亲测可以使用~

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。