npm安装axios
npm install axios --save引入axios
import axios from 'axios'使用axios
mounted () { this.getHomeInfo() }, methods: { getHomeInfo () { //跨域请求可以在config/index.js中进行配置 axios.get('/zt/api/app_dujia/index.php') .then(this.getHomeInfoSucc) }, getHomeInfoSucc (res) { console.log(res) } }
开发环境配置请求接口config/index.js配置多个跨域接口
proxyTable: { '/api' : { target: 'https://touch.dujia.qunar.com', changeOrigin: true, pathRewrite: { '^/api': '' } }, '/zt' : { target: 'https://zt.dujia.qunar.com', changeOrigin: true, pathRewrite: { '^/zt': '' } } },
参考链接:【VUE】一个简单常用的proxyTable配置参考链接:webpack中代理配置(proxyTable)使用webpack+axios修改ProxyTable错误之504axios与jsonp————————————————版权声明:本文为博主「weixin_43756060」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。原文链接:https://blog.csdn.net/weixin_43756060/article/details/86479904
转载于:https://www.cnblogs.com/PasserByOne/p/11589865.html