question
After the vue project is packaged, I want to access index.html
So when you right-click and open it in the default browser, the following error will be reported:
Access to script at 'file:///Users/xx/2-company/2-hoe/2-work/%E5%8E%9A%E5%BE%B7/shanghe-portal-risk/dist/static/js/index-9b48a81b.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https.
The main thing is that the local file file asks back to prompt cross-domain
You can visit this link: Reference Article
Cause Analysis
The solution is as follows:
The first:
Use anywhere (static file server), which can be installed using npm
npm install anywhere -g
After installation, switch to the folder where index.html is located and run anywhere
anywhere
也可以自定义端口号
anywhere -p 8080
The second type:
Live Server plugin
Search and install the Live Server plugin in the plugin market of vsCode:
After installation, right-click the file to be opened, and the " Open with Live Serve
" option will appear, so that no error will be reported when opening the file:
that's all
Reference link: