使用Bootrap和Vue实现仿百度搜索功能
网络编程 2021-07-04 17:32www.168986.cn编程入门
这篇文章主要介绍了使用Bootrap和Vue实现仿百度搜索功能,非常不错,具有参考借鉴价值,需要的朋友可以参考下
用Vue调用百度的搜索接口,实现简单的搜索功能。
搜索框的样式是基于Bootstrap,对样式做了简单的调整, 使之类似于百度搜索。代码如下
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>百度搜索</title> <style type="text/css"> .gray{ background-color: #eee; } .listyle{ font-size: 16px; line-height: 35px; padding-left: 16px; } .ulstyle{ border:1px solid #c; border-: none; } </style> <link rel="stylesheet" type="text/css" href="bootstrap.min.css" rel="external nofollow" > <script type="text/javascript" src="vue.js"></script> <script type="text/javascript" src="vue-resource.js"></script> <script type="text/javascript"> window.onload = function(){ new Vue({ el: ".container", data: { myData:[], txt:"", nowIndex:-1 }, methods:{ get:function(event){ if(event.keyCode==38 || event.keyCode==40){ return; } if(event.keyCode==13){ window.open("https://.baidu./s?wd="+this.txt); this.txt=""; } this.$http.jsonp("https://sp0.baidu./5a1Fazu8AA54nxGko9WTAnF6hhy/su",{ wd:this.txt },{ jsonp:"cb" }).then(function(res){ this.myData=res.data.s },function(res){ alert(res.status); }); }, changeDown:function(){ this.nowIndex++; if(this.nowIndex==this.myData.length){ this.nowIndex=0; this.txt=this.myData[0]; }else{ this.txt=this.myData[this.nowIndex]; } }, changeUp:function(){ this.nowIndex--; if(this.nowIndex==-1){ this.nowIndex=this.myData.length-1; this.txt=this.myData[this.nowIndex]; }else{ this.txt=this.myData[this.nowIndex]; } }, mouseOver:function(n){ this.nowIndex=n; this.txt=this.myData[this.nowIndex]; }, getMsg:function(){ window.open("https://.baidu./s?wd="+this.txt); this.txt=""; } } }); } </script> </head> <body> <br> <div class="container"> <div class="input-group"> <input type="text" class="form-control input-lg" placeholder="请输入关键字" v-model="txt" @keyup="get($event)" @keydown.down="changeDown()" @keydown.up="changeUp()"> <span class="input-group-btn"> <button class="btn btn-default btn-lg" type="button" @click="getMsg()">搜索</button> </span> </div> <ul class="list-unstyled ulstyle" v-show="myData.length!=0"> <li v-for="item in myData" :class={gray:$index==nowIndex,listyle:true} @mouseover="mouseOver($index)" @click="getMsg()">{{item}}</li> </ul> </div> </body> </html>
实现效果如下
以上所述是长沙网络推广给大家介绍的使用Bootrap和Vue实现仿百度搜索功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,长沙网络推广会及时回复大家的。在此也非常感谢大家对狼蚁SEO网站的支持!
编程语言
- 宿迁百度关键词排名指南:实现精准营销的关键
- 四川SEO优化怎么做网络推广
- 立昂技术备案老域名收购:如何为您的业务赋能
- 安徽百度关键词seo贵不贵,一般需要多少钱
- 吉林百度快照排名怎么做电话营销
- 多伦新手做SEO怎么做
- 甘肃优化关键词排名推广怎么做论坛营销
- 沙雅SEO网站推广:提升您的在线可见性
- 四川SEO优化如何提升销售额和销售量
- 聂荣网站排名优化:提升网站可见性的全方位指
- 涞水SEO:提升地方企业在线可见性的策略
- 辽宁百度seo排名怎样做网站排名
- 临湘哪有关键词排名优化:提升网站可见度的关
- 黑龙江百度网站优化有没有优惠
- 凉城优化关键词排名推广:提升您的网络可见性
- 萝北整站优化:提升您网站流量和排名的全面指