VUE cross-domain problem Access to XMLHttpRequest at'http://localhost

Problem Description

VUE cannot request correct data when sending the request, the console is as follows
Insert picture description here

Access to XMLHttpRequest at 'http://localhost:8000/equip_fault_report/all' from origin 'http://localhost:8080' has been 
blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

The URL in my request js is like this
Insert picture description here

solution

Write the following in the configuration js

devServer: {
        proxy: {
            '/api': {
                target: 'http://localhost:8000',
                changeOrigin: true,
                pathRewrite: {
                    '/api': ''
                }
            }
        }
    }

It is interpreted as adding link headers, enabling cross-domain, and adding /api as identification.
It means the link under the request/api, which directly returns to the target

Insert picture description here
The URL of the request js is as follows
Insert picture description here

solve

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_41170600/article/details/108539840