vue打包报错,访问html文件报错
具体什么原因暂不清楚,只是有了解决方案,如果有大佬了解请指教
报错提示:
index.html:1 Access to script at 'file:///C:/js/chunk-vendors.e399ec81.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.

预览nginx 与 vue
1. 下载nginx
- nginx下载 :http://nginx.org/en/download.html

- 文件包目录

2. 预览vue项目
-
vue.config.js 配置代理  -
npm run build 开始打包 == 并打包成 dist文件 
开始解决
- vscode打开已经下载好的nginx文件包
- 打开 conf =》nginx.conf 文件
- listen 默认端口是80 【此处可以自定义端口号,我自定义是5000】
- 在serve对象中增加 访问路径
# /api/ 对应 vue.config.js 代理名称
location /api/ {
# 路径对应vue.config.js 访问的后端路径
proxy_pass http://gmall-h5-api.atguigu.cn;
}
??注意
1. 如果访问文件并且后端接口返回路径 请注意 proxy_pass 对应路径知否一致
2. listen 可自定义端口

- 将dist文件内容复制到 nginx文件包上的html文件中

-
开始运行  -
浏览器访问 http://localhost:5000/ 即可打开项目不会报错

??注意:如果修改 nginx.conf文件中内容 还要重新双击 nginx.eve 文件
浏览器刷新 或者重新输入对应端口号即可
|