国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

使用 Vue.js 仿百度搜索框的實(shí)例代碼

2024-05-06 15:17:26
字體:
供稿:網(wǎng)友

整理文檔,搜刮出一個(gè)使用 Vue.js 仿百度搜索框的實(shí)例代碼,稍微整理精簡一下做下分享。

<!DOCTYPE html><html><head>  <meta charset="utf-8">  <title>Vue demo</title>  <style type="text/css">  .bg {    background: #ccc;  }  </style>  <script src="https://cdn.bootcss.com/vue/2.1.7/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: function(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;          })        },        down: function() {          this.nowIndex++;          if (this.nowIndex == this.result.length) {            this.nowIndex = -1;            this.inputText = this.text;          }        },        up: function() {          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">    <input type="text" placeholder="請(qǐng)輸入搜索內(nèi)容" v-model='inputText' @keyup='show($event)' @keydown.down='down()' @keydown.up.prevent='up()'>    <ul>      <li v-for="(item, index) in result" :class='{bg: index==nowIndex}'>        {{item}}      </li>    </ul>  </div></body></html>

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持錯(cuò)新站長站。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 化州市| 龙岩市| 汽车| 岢岚县| 巴马| 咸丰县| 乌恰县| 仁化县| 崇仁县| 临潭县| 黑龙江省| 蕉岭县| 金川县| 昭觉县| 大关县| 洞口县| 五大连池市| 天镇县| 房产| 隆昌县| 宁波市| 东乡| 江城| 余庆县| 正定县| 东兰县| 本溪| 珲春市| 丹棱县| 白银市| 商都县| 高清| 吐鲁番市| 高青县| 灵石县| 平南县| 龙南县| 石棉县| 肥乡县| 遵化市| 子洲县|