SoFunction
Updated on 2025-04-05

Related introduction to cross-domain settings under vue

This article introduces the relevant introduction to cross-domain settings under vue. It is shared with you. The details are as follows:

1. When using vue development, cross-domain issues are often involved. In fact, there are files in vue cli that we set cross-domain requests.

2. When cross-domain requests cannot be requested, we can modify the dev:{} part in the config folder under the project.

dev: {

  env: require('./'),
  port: 8080,
  autoOpenBrowser: false,
  assetsSubDirectory: 'static',
  assetsPublicPath: '/',
  proxyTable: {
    '/api': {
      target: '/v2',
      changeOrigin: true,
      pathRewrite: {
        '^/api': ''
      }
    }
  },
  // CSS Sourcemaps off by default because relative paths are "buggy"
  // with this option, according to the CSS-Loader README
  // (/webpack/css-loader#sourcemaps)
  // In our experience, they generally work as expected,
  // just be aware of this issue when enabling this option.
  cssSourceMap: false
}

Set target to the domain name we need to access.

3. Then set the global properties in:

 = '/api'

4. At this point, we can use this domain name globally, as follows:

var url =  + '/movie/in_theaters'
  this.$(url).then(res => {
    = ;
  },res => {
   ('Call failed');
  });

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.