Vue2.0 vue-source.js jsonp demo vue跨域请求

以调用百度的输入提示接口为例

=================================================================================================================================

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

=================================================================================================================================

 

 

main.js

import Vue from 'vue'
import VueResouse from 'vue-resource'
import App from './App.vue'
Vue.use(VueResouse)
new Vue({
  el: '#app',
  render: h => h(App)
});

 App.vue

<script>
export default {
  name: 'app',
  data () {
    return {
      myData:[],
      v1:""
    }
  },
  methods:{
    show:function(){
      this.$http.jsonp("https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su",
      {//请求参数
        params: {
          wd:this.v1
        },
        jsonp:'cb'
      }).then(function(res){
        console.log(JSON.parse(res.bodyText).s)
        this.myData = JSON.parse(res.bodyText).s
        console.log(this.myData)
      },function(){
        //console.log(1)
      });
    }
  }
}
</script> 

 

posted @ 2016-11-07 17:53  幽竹小妖  阅读(21210)  评论(0编辑  收藏  举报