2019-03-12 15:50:33 1196瀏覽
今天扣丁學(xué)堂HTML5培訓(xùn)老師給大家分享一篇關(guān)于vue實現(xiàn)百度下拉列表交互操作示例的詳細介紹,希望對同學(xué)們學(xué)習HTML5開發(fā)有所幫助,下面我們一起來看一下吧。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>www.jb51.net vue百度下拉列表</title> <style> .gray{ background: #ccc; } </style> <script src="vue.js"></script> <script src="vue-resource.js"></script> <script> window.onload=function(){ new Vue({ el:'body', data:{ myData:[], t1:'', now:-1//按上下鍵,當前選中 }, methods:{ get:function(ev){ if(ev.keyCode==38 || ev.keyCode==40)return; if(ev.keyCode==13){ window.open('https://www.baidu.com/s?wd='+this.t1); this.t1=''; } this.$http.jsonp('https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su',{ wd:this.t1 },{ jsonp:'cb' }).then(function(res){ this.myData=res.data.s; },function(){ }); }, changeDown:function(){ this.now++; if(this.now==this.myData.length)this.now=-1//走到最下面那個,就返回最上面那個; this.t1=this.myData[this.now];//搜索框的值對應(yīng)變化 }, changeUp:function(){ this.now--; if(this.now==-2)this.now=this.myData.length-1; this.t1=this.myData[this.now]; } } }); }; </script> </head> <body> <div id="box"> <input type="text" v-model="t1" @keyup="get($event)" @keydown.down="changeDown()" @keydown.up.prevent="changeUp()"> <!--搜索框的光標會默認定位到文字前面,這里@keydown.up.prevent阻止默認事件--> <ul> <li v-for="value in myData" :class="{gray:$index==now}"> {{value}} </li> </ul> <p v-show="myData.length==0">暫無數(shù)據(jù)...</p> </div> </body> </html>
感興趣的朋友可以使用在線HTML/CSS/JavaScript代碼運行工具,最后想要了解更多關(guān)于HTML5開發(fā)方面內(nèi)容的小伙伴,請關(guān)注扣丁學(xué)堂HTML5培訓(xùn)官網(wǎng)、微信等平臺,扣丁學(xué)堂IT職業(yè)在線學(xué)習教育平臺為您提供權(quán)威的HTML5視頻教程供學(xué)員學(xué)習,HTML5培訓(xùn)后的前景無限,行業(yè)薪資和未來的發(fā)展會越來越好的,扣丁學(xué)堂老師精心推出的HTML5視頻直播課定能讓你快速掌握HTML5從入門到精通開發(fā)實戰(zhàn)技能??鄱W(xué)堂H5技術(shù)交流群:673883249。
【關(guān)注微信公眾號獲取更多學(xué)習資料】
查看更多關(guān)于“HTML5開發(fā)技術(shù)資訊”的相關(guān)文章>>