出现问题
本地直接打开dist文件夹会报错,报错信息类似于:
Access to script at 'file:///D:/assets/index.9cb0ffcc.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: chrome, chrome-extension, chrome-untrusted, data, http, https, isolated-app.
解决方法
1.全局安装服务支持 http-sever:
npm install http-server -g
2.进入打包后的dist文件夹,运行cmd,输入下方命令行,开启一个服务,端口号设置不冲突即可:
http-server -p 8090 // 8090为自己设置的端口号,不要跟之前打开的冲突即可
完成后即可正常访问项目