vue-cli 3.0 跨域请求代理
生活随笔
收集整理的這篇文章主要介紹了
vue-cli 3.0 跨域请求代理
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
官方文檔中指明,跨域請求可以通過配置vue.config.js中的devServer.proxy選項(xiàng)來進(jìn)行配置。
這個(gè)選項(xiàng)配置的本質(zhì)實(shí)際上就是http-proxy-middleware中間件的用法,和Webpack-dev-server的proxy一樣。
vue-cli 3.0中介紹了兩種常見的用法:
module.exports = {devServer: {proxy: 'http://localhost:4000'} }這種用法是將任何未知請求 (沒有匹配到靜態(tài)文件的請求) 代理到http://localhost:4000
如果想單獨(dú)配置,可以使用path: options成對的對象進(jìn)行配置
module.exports = {devServer: {proxy: {'/api': {target: 'http://localhost:4000',ws: true,changeOrigin: true},'/foo': {target: 'http://localhost:8000'}}} }上述配置指明:
將請求到/api/xxx代理到http://localhost:4000/api/xxx,
將請求到/foo/xxx代理到http://localhost:8000/foo/xxx
其他詳細(xì)配置可以百度http-proxy-middleware配置
總結(jié)
以上是生活随笔為你收集整理的vue-cli 3.0 跨域请求代理的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: git-ftp Can't access
- 下一篇: MySQL用户及权限管理