这篇文章主要介绍了vue.js中添加favicon图标的方法,具有一定借鉴价值,需要的朋友可以参考下。希望大家阅读完这篇文章后大有收获。下面让小编带着大家一起了解一下。
vue.js添加favicon图标的方法:1、修改【index.html】文件,代码为【<link rel="shortcut icon" type="image/x-icon" href="favico】;2、修改webpack配置文件。
vue.js添加favicon图标的方法:
方法一:修改index.html文件
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico"/>
缺点:打包后需要将favicon.ico
复制到根目录
方法二:修改webpack配置文件
1、找到build下的webpack.dev.conf.js文件
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'index.html',
inject: true,
favicon: path.resolve('favicon.ico') // 新增
}),
2、找到build下的webpack.prod.conf.js文件
new HtmlWebpackPlugin({
filename: config.build.index,
template: 'index.html',
inject: true,
favicon: path.resolve('favicon.ico'), //新增
minify: {
emoveComments: true,
collapseWhitespace: true,
removeAttributeQuotes: true
...
}),
方法三 :vue项目打包后favicon无法正常显示
解决方法:
在webpack.prod.config.js中的HtmlWebpackPlugin插件选项中配置favicon选项,其中favicon的路径是个相对路径
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'index.html',
favicon: 'src/assets/img/favicon.ico',
inject: true
}),
修改配置文件后需重启npm run dev
打包后根目录下就会有favicon.ico
感谢你能够认真阅读完这篇文章,希望小编分享vue.js中添加favicon图标的方法内容对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,遇到问题就找亿速云,详细的解决方法等着你来学习!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。