Vue 脚手架配置代理
生活随笔
收集整理的這篇文章主要介紹了
Vue 脚手架配置代理
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、在 vue.config.js 中添加配置
devServer: {proxy: 'http://localhost:5000' }二、具體代理規則:
module.exports = {devServer: {proxy: {'/api1': { // 配置所有以 /api1 開頭的請求路徑target: 'http:localhost:5000', // 代理目標的地址changeOrigin: true,pathRewrite: {'^/api1': ''}},'/api2': {target: 'http:localhost:5000',changeOrigin: true,pathRewrite: {'^/api2': ''}},}} }/*changeOrigin : true(默認) --> 服務器收到的請求頭中的 host 為:localhost:5000changeOrigin : false --> 服務器收到的請求頭中的 host 為:localhost:8080 */三、使用 vue-resource 發送請求(方式和 axios 一樣)
總結
以上是生活随笔為你收集整理的Vue 脚手架配置代理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 整理:C++中sprintf()函数的使
- 下一篇: 14个你可能不知道的JavaScript