input的type=“serch”
监听keypress事件
阻止事件默认行为(默认为换行)
通过event.target.value获取要搜索的值
处理ios上系统软键盘,keycode=13的叫换行问题,提升客户体验。
input 外面包一层form,并且阻止表单的默认行为
<form @submit.prevent>
<input type="serch" placeholder="商品搜索~" v-model="searchVal" @keypress="searchGoods">
</form>
searchGoods (event) {
if (event.keyCode == 13) {
event.preventDefault(); //禁止默认事件(默认是换行)
this.$router.push('/goods-list?id=&productName='+this.searchVal);//带着搜索值跳转
}
}