国产探花免费观看_亚洲丰满少妇自慰呻吟_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>

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 冕宁县| 综艺| 楚雄市| 洪江市| 武乡县| 施秉县| 论坛| 昂仁县| 宕昌县| 宁化县| 安化县| 南城县| 梨树县| 万年县| 嘉祥县| 新野县| 多伦县| 如皋市| 朝阳区| 方正县| 本溪| 湘乡市| 北流市| 扎鲁特旗| 武川县| 兰考县| 建宁县| 彰化市| 南部县| 郎溪县| 达州市| 田东县| 宁陕县| 阳春市| 马鞍山市| 邵阳市| 湘潭县| 黎平县| 阿克| 龙井市| 宁远县|