Vue 需要使用jsonp解决跨域时,可以使用(vue-jsonp)

1,执行命令

npm install vue-jsonp --save

2、src/main.js中添加:

import VueJsonp from 'vue-jsonp'
Vue.use(VueJsonp)

3、其它组件中基本使用方法:

let obj = {
                    'location':item.point.lat+','+item.point.lng,
                    'output':'json',
                    'ak':'***'
                }
                this.$jsonp('https://api.map.baidu.com/geocoder/v2/', obj).then(res => {
                  console.log(res)
                    this.
                }).catch(err => {
                  console.log(err)
                })

更多==》》》https://www.npmjs.com/package/vue-jsonp

posted @ 2019-01-17 12:47  Gavin1024  阅读(8044)  评论(1编辑  收藏  举报