记录今天的一个需求,动态设置网页标签栏的图标:
index.html中
<link rel="icon" type="image/png" href="<%= BASE_URL %>favicon/favicon-64x64.png" sizes="64x64">
在动态设置favicon.ico的vue文件中:
// 设置网站图片
const favicon = document.querySelector('link[rel="icon"]');
const timestamp = new Date().getTime(); // 获取当前时间戳
favicon.href = `${process.env.BASE_URL}favicon/rz_favicon.ico?t=${timestamp}`;