最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于Vue.js 2.0實(shí)現(xiàn)百度搜索框效果

 更新時(shí)間:2020年12月28日 15:04:49   作者:Mr.曹  
這篇文章主要為大家詳細(xì)介紹了基于Vue.js 2.0實(shí)現(xiàn)百度搜索框效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

使用Vue.js 2.0 模仿百度搜索框效果,供大家參考,具體內(nèi)容如下

<!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8">
 <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=2.0, maximum-scale=1.0, minimum-scale=1.0">
 <title>Vue模擬百度搜索</title>
 <style type="text/css">
 body, html{
 padding: 0;
 margin: 0;
 }
 #box{
 margin-top: 80px;
 display: flex;
 flex-direction: column;
 align-items: center;
 justify-content: center;
 }
 .input{
 width: 500px;
 height: 30px;
 text-indent: 4px;
 }
 .baidu input{
 height: 30px;
 cursor: pointer;
 color: #fff;
 letter-spacing: 1px;
 background: #3385ff;
 border: 1px solid #2d78f4;
 }
 ul{
 padding: 0;
 margin-top: 6px;
 }
 li{
 list-style: none;
 margin: 4px;
 }
 li:hover{
 background: #ccc;
 }
 .bgcolor {
 background: #ccc;
 }
 </style>
 <script src="https://cdn.bootcss.com/vue/2.4.2/vue.min.js"></script>
 <script src="https://cdn.bootcss.com/vue-resource/1.3.1/vue-resource.min.js"></script>
 <script type="text/javascript">
 window.onload = function() {
 new Vue({
  el: '#box',
  data: {
  inputText: '',
  text: '',
  nowIndex: -1,
  result: []
  },
  methods: {
  show (ev) {
   if (ev.keyCode == 38 || ev.keyCode == 40) {
   if (this.nowIndex < -1){
    return;
   }
   if (this.nowIndex != this.result.length && this.nowIndex != -1) {
    this.inputText = this.result[this.nowIndex];
   }
   return;
   }
   if (ev.keyCode == 13) {
   window.open('https://www.baidu.com/s?wd=' + this.inputText, '_blank');
   this.inputText = '';
   }
   this.text = this.inputText;
   this.$http.jsonp('https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su', {
   params: {
    wd: this.inputText
   },
   jsonp: 'cb'
   }).then(res => {
   this.result = res.data.s;
   })
  },
  goto () {
   window.open('https://www.baidu.com/s?wd=' + this.inputText, '_blank');
   this.inputText = '';
  },
  gotoItem(item) {
   window.open('https://www.baidu.com/s?wd=' + item, '_blank');
   this.inputText = '';
  },
  down () {
   this.nowIndex++;
   if (this.nowIndex == this.result.length) {
   this.nowIndex = -1;
   this.inputText = this.text;
   }
  },
  up () {
   this.nowIndex--;
   if (this.nowIndex < -1){
   this.nowIndex = -1;
   return;
   }
   if (this.nowIndex == -1) {
   this.nowIndex = this.result.length;
   this.inputText = this.text;
   }
  }
  }
 });
 }
 </script>
</head>
 
<body>
 <div id="box">
 <img src="https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png" width="270" height="129">
 <div>
  <div>
  <input 
   type="text" 
   class="input" 
   placeholder="請(qǐng)輸入搜索內(nèi)容 " 
   v-model='inputText' 
   @keyup='show($event)' 
   @keydown.down='down()' 
   @keydown.up.prevent='up()'
  >
  <span class="baidu" @click="goto()">
   <input type="submit" value="百度一下" >
  </span>
  </div>
  
  <ul>
  <li v-for="(item, index) in result" :class='{bgcolor: index==nowIndex}' @click="gotoItem(item)">
   {{item}}
  </li>
  </ul>
 </div>

 </div>
</body> 
</html>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 詳解使用VueJS開(kāi)發(fā)項(xiàng)目中的兼容問(wèn)題

    詳解使用VueJS開(kāi)發(fā)項(xiàng)目中的兼容問(wèn)題

    這篇文章主要介紹了詳解使用VueJS開(kāi)發(fā)項(xiàng)目中的兼容問(wèn)題,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-08-08
  • vue中van-picker的選項(xiàng)插槽的使用

    vue中van-picker的選項(xiàng)插槽的使用

    這篇文章主要介紹了vue中van-picker的選項(xiàng)插槽的使用,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-01-01
  • Vue的路由配置過(guò)程(Vue2和Vue3的路由配置)

    Vue的路由配置過(guò)程(Vue2和Vue3的路由配置)

    這篇文章回顧了Vue2和Vue3中路由的配置步驟,包括安裝正確的路由版本、創(chuàng)建路由實(shí)例、配置routes以及在入口文件中注冊(cè)路由,Vue2中使用Vue.use(VueRouter),而Vue3中使用createRouter和createWebHashHistory
    2025-01-01
  • 在vant中如何使用dialog彈窗

    在vant中如何使用dialog彈窗

    這篇文章主要介紹了在vant中如何使用dialog彈窗,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-05-05
  • 解決vue+elementui項(xiàng)目打包后樣式變化問(wèn)題

    解決vue+elementui項(xiàng)目打包后樣式變化問(wèn)題

    這篇文章主要介紹了解決vue+elementui項(xiàng)目打包后樣式變化問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-08-08
  • vue3?組合式api中?ref?和$parent?的使用方法

    vue3?組合式api中?ref?和$parent?的使用方法

    vue3中, 在 組件中添加一個(gè) component ref=“xxx” ,就可以在父組件中得到 子組件的 dom 對(duì)象, 以及 虛擬的 dom 對(duì)象, 有了虛擬 dom, 我們就可以在父組件中控制子組件的顯示了,這篇文章主要介紹了vue3組合式api中ref和$parent的使用,需要的朋友可以參考下
    2023-09-09
  • vue跳轉(zhuǎn)頁(yè)面常用的4種方法與區(qū)別小結(jié)

    vue跳轉(zhuǎn)頁(yè)面常用的4種方法與區(qū)別小結(jié)

    這篇文章主要給大家介紹了關(guān)于vue跳轉(zhuǎn)頁(yè)面常用的4種方法與區(qū)別,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2022-03-03
  • 解析vue.js中常用v-指令

    解析vue.js中常用v-指令

    本文以click為例給大家介紹vue.js中常用v-指令,可以用 v-on 指令監(jiān)聽(tīng) DOM 事件,并在觸發(fā)時(shí)運(yùn)行一些 JavaScript代碼,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧
    2021-10-10
  • 記一次用ts+vuecli4重構(gòu)項(xiàng)目的實(shí)現(xiàn)

    記一次用ts+vuecli4重構(gòu)項(xiàng)目的實(shí)現(xiàn)

    這篇文章主要介紹了記一次用ts+vuecli4重構(gòu)項(xiàng)目的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-05-05
  • vue 監(jiān)聽(tīng) Treeselect 選擇項(xiàng)的改變操作

    vue 監(jiān)聽(tīng) Treeselect 選擇項(xiàng)的改變操作

    這篇文章主要介紹了vue 監(jiān)聽(tīng) Treeselect 選擇項(xiàng)的改變操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-08-08

最新評(píng)論

兴义市| 海伦市| 北流市| 乡宁县| 民乐县| 宁远县| 和政县| 亳州市| 丰原市| 葫芦岛市| 额尔古纳市| 黎平县| 汝州市| 锡林浩特市| 晴隆县| 桑日县| 天气| 张家口市| 洪泽县| 华容县| 南阳市| 文登市| 宜都市| 东阳市| 阳高县| 阿勒泰市| 台东市| 富源县| 罗甸县| 北碚区| 日喀则市| 阜城县| 凯里市| 通许县| 汽车| 肇州县| 加查县| 桐柏县| 高碑店市| 镇安县| 辽宁省|