vue项目切换区划来更新href上的favicon图标文件
2020-07-14 本文已影响0人
小呆糊总
index.html代码文件
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>***</title>
</head>
<body>
<div id="app"></div>
</body>
<script>
//判断本地缓存里的区划是不是某省区划,决定href的图标用什么显示
(function() {
var regioncode = getCookie('regioncode')
// console.log(regioncode)
var link = document.querySelector("link[rel*='icon']") || document.createElement('link');
link.type = 'image/x-icon';
link.rel = 'shortcut icon';
if(regioncode.slice(0,2) == '61'){//某省用某省的图标
link.href = '../***.ico';
}else{//其他用默认图标
link.href = '../favicon.ico';
}
document.getElementsByTagName('head')[0].appendChild(link);
})();
//获取本地的cookie里的regioncode,判断当前是不是某省的区划,
function getCookie(name){
var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
if(arr=document.cookie.match(reg))
return unescape(arr[2]);
else
return null;
}
</script>
</html>
build/webpack.dev.conf.js与build/webpack.prod.conf.js里的new HtmlWebpackPlugin中的favicon要注销掉
plugins: [
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'index.html',
inject: true,
// favicon: path.resolve('favicon.ico'),
path: config.dev.assetsPublicPath,
}),
]