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'
	        }
	      }
	    }
	  }
	}


发布了103 篇原创文章 · 获赞 19 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/M106588L/article/details/100597489