<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.gray{
background: #ccc
}
</style>
</head>
<body>
<div id="box">
<input type="text" v-model="t1" @keyup="get($event)" @keydown.down="changeDown()" @keydown.up.prevent="changeUp()">
<ul>
<li v-for="value in myData" :class="{gray:$index==nowIndex}">
{{value}}
</li>
</ul>
<p v-show="myData.length==0">暫無數(shù)據(jù)...</p>
</div>
<script src="vue.js"></script>
<script src="vue-resource.js"></script>
<script>
new Vue({
el:"#box",
data:{
myData:[],
t1:'',
nowIndex:-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;
console.log(res.data);
},function(err){
console.log(err)
})
},
changeDown:function(){
this.nowIndex++;
if(this.nowIndex==this.myData.length){
this.nowIndex=-1;
}
this.t1=this.myData[this.nowIndex]
},
changeUp:function(){
this.nowIndex--;
if(this.nowIndex==-2){
this.nowIndex=this.myData.length-1;
}
this.t1=this.myData[this.nowIndex]
}
}
})
</script>
</body>
</html>
vue 1.0 模仿百度搜索下拉框
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- 林二平七歲時(shí)夢(mèng)到過一個(gè)女鬼。 其實(shí)這女鬼本也不算一個(gè)女鬼,只是在他的夢(mèng)中略顯恐怖。他記著這是白天電視里那個(gè)身世凄涼...
- 文/紅樹林 萬事開頭難?我不怕。但我怕什么事都不敢開頭,開頭了又堅(jiān)持不到最后,哪怕一件小小的事情,也需要很大的勇氣...