zoukankan      html  css  js  c++  java
  • vue

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>study百度下拉列表</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <style>
            .gray{
                background: #ccc;
            }
        </style>
        <script src="vue.js"></script>
        <script src="vue-resource.js"></script>
        <script>
            window.onload=function(){
                new Vue({
                    el:'body',
                    data:{
                        myData:[],//下面列表的数据展示
                        t1:'',
                        now:-1
                    },
                    methods:{
                        get:function(ev){
                           this.$http.jsonp("https://www.baidu.com/sugrec?prod=pc&sugsid=1454,21107,28773,28723,28963,28833,28585,28603",{
                               wd:this.t1
                           },{
                               jsonp:"cb"
                           }).then(function(res){
                               this.myData=res.data.g
                           })
                        },
                        changeDown:function(){
                            this.now++;
                            if(this.now>this.myData.length-1){this.now=0}
                            this.t1=this.myData[this.now].q
                        }
                    }
                });
            };
        </script>
    </head>
    <body>
        <div id="box">
           <input v-model="t1" type="text" @keyup="get($event)" @keydown.down="changeDown($event)">
           <ul>
               <li  v-for="item in myData" :class="{gray:$index==now}">{{item.q}}</li>
           </ul>
            <p v-show="myData.length==0">暂无数据。。。</p>
        </div>
    </body>
    </html>
  • 相关阅读:
    Python 基础
    Python 基础
    Python 基础
    Python 基础
    Python 基础
    Python 基础
    Python 基础
    Python 基础
    Python 基础
    Python 基础
  • 原文地址:https://www.cnblogs.com/pengfei25/p/10827200.html
Copyright © 2011-2022 走看看