[Solved] Axios Cross-domain issues: No ‘Access-Control-Allow-Origin‘ header is present on the requested resource.

Cross domain problems of Axios

Problem Description:

After using Vue + Axios development for post request, the cross domain problem in the following picture appears


Read some relevant information on the Internet, and finally found a solution

module.exports = {
    dev: {
        proxyTable: {
      '/api': {
        port: 3000,
        target: '',
        chunkOrigins: true,
        pathRewrite: {
          '^api': ''

Modify the proxytable in the index.js file in the config directory

Chunkorigins is whether to turn on cross domain

          url: '/api/sysUser/selectUserInfo',
          method: 'POST'
        }).then(res => {
        }).catch(res => {
          console.log('error' + res);

Modifying Axios in Vue component method

Restart the project and send the post request again, and the program is normal


Similar Posts: