UNPKG

vue-hooks-plus

Version:
25 lines (24 loc) 765 B
"use strict"; const vue = require("vue"); const UseFaviconImgTypeMap = { SVG: "image/svg+xml", ICO: "image/x-icon", GIF: "image/gif", PNG: "image/png" }; function useFavicon(href) { const _href = vue.computed(() => vue.unref(href)); vue.watchEffect(() => { var _a; if (!_href.value) return; const cutUrl = (_a = _href.value) == null ? void 0 : _a.split("."); const imgSuffix = cutUrl[cutUrl.length - 1].toLocaleUpperCase(); const link = document.querySelector("link[rel*='icon']") || document.createElement("link"); link.type = UseFaviconImgTypeMap[imgSuffix]; link.href = _href.value; link.rel = "shortcut icon"; document.getElementsByTagName("head")[0].appendChild(link); }); } module.exports = useFavicon;