在 config 目录的 index.js 文件中 设置 proxyTable 的值,样式如下
proxyTable: { '/api':{ target:'http://10.144.26.240:9300', changeOrigin:true, pathRewrite: { '^/api': '' } } }然后再进行请求就OK了
methods: { reverseMessage: function() { this.$http.get(this.apiUrl) .then((response) => { console.log(response) this.msg = 'success' }) .catch(function(response) { console.log(response) this.msg = response }) } }
本文介绍如何通过配置代理来解决前端开发中的跨域问题。具体步骤是在项目的config目录下的index.js文件中设置proxyTable的值,将目标API地址指向本地开发服务器,同时通过pathRewrite重写路径。
481

被折叠的 条评论
为什么被折叠?



