方法有多种这里暂时记录使用的一种
在index.html 模板中添加
<link rel="shortcut icon" href=/static/whtericon.ico>
其中href就是你的图标地址,且图标必须在static中
后续就可以在script 中根据
window.location.href 来判断是否是需要更改的页面
是就替换<link>中的href 地址 如:
let url = window.location.href;
const link = document.querySelector('link[rel*=\'icon\']') || document.createElement('link');
let whter = '/static/whtericon.ico';
let irr = '/static/irricon.ico';
// let whter = '/whtericon.ico';
// let irr = '/irricon.icoico';
link.type = 'image/x-icon';
link.rel = 'shortcut icon';
if (url.indexOf('saveWater')>-1){
link.href = irr;
}else {
link.href = whter;
}
document.getElementsByTagName('head')[0].appendChild(link);
}
全部代码