在使用
uni-app
开发前端,发布为H5
形式的时候,浏览器标题的左上角会有Vue
默认的标志,如下图所示,我们希望把它替换成需要的新图标。
Gitee参考代码
首先把要修改的图标文件放在static
目录下,并重命名为favicon.ico
,然后在根目录下新建template.html
文件,粘贴以下代码到template.html
中
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>
<%= htmlWebpackPlugin.options.title %>
</title>
<script>
document.addEventListener('DOMContentLoaded', function() {
document.documentElement.style.fontSize = document.documentElement.clientWidth / 20 + 'px'
})
</script>
<link rel="stylesheet" href="<%= BASE_URL %>./static/index.<%= VUE_APP_INDEX_CSS_HASH %>.css" />
<link rel="icon" type="image/png" sizes="32x32" href="./static/favicon.ico">
</head>
<body>
<noscript>
<strong>Please enable JavaScript to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
双击manifest.json
打开配置菜单,切换到H5配置,在index.html
模版路径中填入template.html
,保存所有修改。
调试运行,显示结果如下,默认图标修改成功!
参考资料
[1] https://www.cnblogs.com/wbl001/p/12330792.html
[2] https://www.cnblogs.com/niceyoo/p/12215860.html