欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

基于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)文章

  • react router零基礎(chǔ)使用教程

    react router零基礎(chǔ)使用教程

    React-Router 路由庫(kù),是官方維護(hù)的路由庫(kù),事實(shí)上也是唯一可選的路由庫(kù)。它通過(guò)管理 URL,實(shí)現(xiàn)組件的切換和狀態(tài)的變化,開(kāi)發(fā)復(fù)雜的應(yīng)用幾乎肯定會(huì)用到
    2022-09-09
  • VScode更新后安裝vetur仍無(wú)法格式化vue文件的解決

    VScode更新后安裝vetur仍無(wú)法格式化vue文件的解決

    這篇文章主要介紹了VScode更新后安裝vetur仍無(wú)法格式化vue文件的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-10-10
  • 詳解使用vue實(shí)現(xiàn)tab 切換操作

    詳解使用vue實(shí)現(xiàn)tab 切換操作

    這篇文章主要介紹了詳解使用vue實(shí)現(xiàn)tab操作,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-07-07
  • Vue3中v-if和v-for優(yōu)先級(jí)實(shí)例詳解

    Vue3中v-if和v-for優(yōu)先級(jí)實(shí)例詳解

    Vue.js中使用最多的兩個(gè)指令就是v-if和v-for,下面這篇文章主要給大家介紹了關(guān)于Vue3中v-if和v-for優(yōu)先級(jí)的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-09-09
  • Vue實(shí)現(xiàn)戶籍管理系統(tǒng)戶籍信息的添加與刪除方式

    Vue實(shí)現(xiàn)戶籍管理系統(tǒng)戶籍信息的添加與刪除方式

    這篇文章主要介紹了Vue實(shí)現(xiàn)戶籍管理系統(tǒng)戶籍信息的添加與刪除方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-09-09
  • Vue使用v-bind動(dòng)態(tài)綁定CSS樣式

    Vue使用v-bind動(dòng)態(tài)綁定CSS樣式

    這篇文章給大家介紹了Vue使用v-bind動(dòng)態(tài)綁定CSS樣式,文中有相關(guān)的代碼示例供大家參考,對(duì)大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下
    2024-02-02
  • 解決element-ui el-checkbox的一些坑

    解決element-ui el-checkbox的一些坑

    這篇文章主要介紹了解決element-ui el-checkbox的一些坑,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-04-04
  • vue Watch和Computed的使用總結(jié)

    vue Watch和Computed的使用總結(jié)

    本文主要介紹Vue.js中監(jiān)聽(tīng)器和計(jì)算屬性的相關(guān)知識(shí)點(diǎn),包括對(duì)普通屬性的監(jiān)聽(tīng)、對(duì)對(duì)象的監(jiān)聽(tīng)、對(duì)數(shù)組的監(jiān)聽(tīng),以及計(jì)算屬性的Set方法,計(jì)算屬性與監(jiān)聽(tīng)器的區(qū)別等等
    2021-05-05
  • Vue自嵌套樹(shù)組件使用方法詳解

    Vue自嵌套樹(shù)組件使用方法詳解

    這篇文章主要為大家詳細(xì)介紹了Vue自嵌套樹(shù)組件的使用方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • Vue項(xiàng)目部署的實(shí)現(xiàn)(阿里云+Nginx代理+PM2)

    Vue項(xiàng)目部署的實(shí)現(xiàn)(阿里云+Nginx代理+PM2)

    這篇文章主要介紹了Vue項(xiàng)目部署的實(shí)現(xiàn)(阿里云+Nginx代理+PM2),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2019-03-03

最新評(píng)論