vue2./vue.3.x實現跨域(proxytable/proxy)

  • vue2.x
    config/index.js
proxyTable: {
      '/api': {
        target: 'http://localhost:3000/', // 請求的接口的域名
        // secure: false,  // 如果是https接口,需要配置這個參數
        changeOrigin: true, // 如果接口跨域,需要進行這個參數配置
        pathRewrite: {
          '^/api': ''
        }
      }
    },

  • vue3.x
    vue.config.js
	module.exports = {
	  devServer: {
	    proxy: {
	      '/api': {
	        target: 'http://localhost:8080/',
	        changeOrigin: true,
	        ws: true,
	        pathRewrite: {
	          '^/api': '/static/mock'
	        }
	      }
	    }
	  }
	}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章