vue 通过jsonp请求百度搜索的接口

   newData() {
                 this.$jsonp('https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su', {
                     wd: this.inputVal, // 这是要百度搜索的字段
                     jsonp:'cb',
                 }).then(res=>{
                     console.log(res)
                 }).catch(err=>{
                     
                 }) 
      一定要在下面用  window.baidu.sug去接收 因为百度传过来是个函数,不然会报找不到该函数 
                 window.baidu={};
                 window.baidu.sug=function(json){
                     console.log(json )
                 }
             }
image.png
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容