vue 各类打包坑

1,报错html

Refused to load the image 'http://localhost:8080/favicon.ico'
 because it violates the following Content Security Policy directive:
 "default-src 'none'". Note that 'img-src' was not explicitly set,
 so 'default-src' is used as a fallback.;

 看不懂吧,翻译一下bootstrap

拒绝加载图像“http://localhost:8080/favicon.ico”

由于它违反了如下内容安全策略指令:

“默认SRC‘none’”。请注意,没有显式设置“img-src”,

因此“default src”用做回退。

 解决办法及缘由:打包的时候,改掉了config文件夹中的index.js里面的assetsPublicPath: ‘/’,的路径,因此才致使了这个报错。改回来就ok了。安全

 

2,点击路由切换报错下面代码,并且一刷新就跳404;服务器

Uncaught SyntaxError: Unexpected token <
Error: Loading chunk 1 failed.
    at HTMLScriptElement.u (bootstrap cda6aba49714b00712f5:103)

 看不懂吧,不懂就对了,我也不懂,可是找到缘由spa

解决办法及缘由:这是由于写路由的时候为了好看使用了 mode:'history' 模式去掉 # 号,可是在服务器是不认识去掉#的好连接的,因此返回一个404页面。这个问题官网解释以下,要使用history模式 须要服务器支持,目前对服务器不了解,因此就简单粗暴不用history模式了,问题就解决了。翻译

3,打包后报错以下htm

Uncaught SyntaxError: Unexpected token <
Uncaught SyntaxError: Unexpected token <
Uncaught SyntaxError: Unexpected token <

 解决办法及缘由:由于config 文件夹下面的 index.js 配置 assetsPublicPath:'/'  引用文件是路径是相对更目录来引用的,但咱们打包后生成的distblog

         文件夹index.html 引入的路径都在当前目录下的static文件夹下,因此只要打包的时候改为assetsPublicPath:'./'就好了,有两处,都要改为'./'哦。token

 

有新的坑在补充。ip

踩到坑才说明在进步。

逆水行舟,难灭凌云之志!

相关文章
相关标签/搜索