axios跨域解决(开发环境下)

410 阅读1分钟

2.x public/index.js

proxyTable: {
  "/api": {
    target: "http://localhost:3000",
    pathRewrite: {
      '^/api': ''
    },
    changeOrigin: true
  }
}

3.x vue.config.js

module.exports = {
    publicPath: process.env.NODE_ENV === 'production'
        ? '/sxt/'
        : '/',
    devServer: {
        // port: 9000,
        proxy: {
            '/api': {
                target: 'http://localhost:3000',
                pathRewrite: {
                    '^/api': ''
                },
                changeOrigin: true
            }
        }
    }
}