Configuring proxy solve cross-domain problems in vue.config.js project

First, we are localhost in local development, domain name, when we need to request background data, there will be cross-domain issues

Here is the configuration file vue.config.js

devServer: {
    proxy: {
      // detail: https://cli.vuejs.org/config/#devserver-proxy
      '/api': {
        target: `http://10.24.4.214:8098/api`,
        changeOrigin: true,
        pathRewrite: {
          '^/api' : ''
        }
      }
    }
}

  / Api url value indicating the need to match the time of the request, and then replace the target

For instance, your pages are written

axios.post('/api/list/gd')

Address of the final node to request background is: http: //10.24.4.214: 8098 / api / list / gd

But you see in the browser is: http: // localhost: 8888 / api / list / gd, this time the problem does not exist spanned, node service agent has to get the data

----------------------

In fact, the real cause of the problem is the security mechanism across browsers

 

Guess you like

Origin www.cnblogs.com/bobo1/p/12588079.html