1、配置代理跨域
config/index.js
proxyTable: {
'/api': {
target: 'http://shuige.wicp.vip/', //目标接口域名
changeOrigin: true, //是否跨域
pathRewrite: {
'^/api': '/' //重写接口 后台接口指向不统一 所以指向所有/
}
},
cssSourceMap: false
},
2、使用jsonp
安装
npm install vue-jsonp --save
main.js
import VueJsonp from 'vue-jsonp'
Vue.use(VueJsonp)
组件中
this.$jsonp('https://api.map.baidu.com/geocoder/v2/', obj).then(res => {
console.log(res)
this.
})