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

首頁 > 編程 > JavaScript > 正文

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

2019-11-19 16:37:41
字體:
來源:轉載
供稿:網友

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

<!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="請輸入搜索內容" 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>

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 伊春市| 伽师县| 衡阳县| 普兰县| 房产| 沂水县| 澄江县| 黑河市| 华容县| 怀安县| 明水县| 老河口市| 西乌珠穆沁旗| 桓台县| 灵璧县| 新和县| 金阳县| 新乡市| 铁岭市| 文山县| 广丰县| 盐池县| 鄂州市| 巧家县| 神木县| 高安市| 旺苍县| 富宁县| 夏邑县| 铜川市| 囊谦县| 深水埗区| 板桥市| 桃江县| 奈曼旗| 阜新| 克什克腾旗| 且末县| 固原市| 酒泉市| 石柱|