html - Nuxt 按页面更改图标
问题描述
在某些情况下,某些路线需要不同的图标。我试过把这段代码放在头上,虽然这确实有效,但它会在前一个图标下方添加另一个图标,并且不会覆盖它。
页面.vue:
head () {
return {
title: 'my website title',
link: [{
rel: 'icon', type: 'image/x-icon', href: 'https://s.yimg.com/rz/l/favicon.ico'
}]
}
}
<link data-n-head="ssr" rel="icon" type="image/x-icon" href="/favicon.ico">
<link data-n-head="ssr" rel="icon" type="image/x-icon" href="https://s.yimg.com/rz/l/favicon.ico">
你如何去覆盖一个网站图标?
解决方案
将 a 添加hid
到 favicon 中nuxt.config.js
:
link: [{
hid: 'icon',
rel: 'icon',
type: 'image/x-icon',
href: 'link-to-fallback-favicon.png'
}]
您现在可以head
使用相同的隐藏在 pages 方法中覆盖它:
head()
return {
link: [{
hid: 'icon',
rel: 'icon',
type: 'image/x-icon',
href: 'link-to-new-favicon.png'
}]
一旦您导航到该页面,Nuxt 将自动覆盖,并在您导航离开时使用 nuxt.config.js 中的常规一次。
推荐阅读
- c++ - 如何从共享内存就地创建 STL 向量/数组?
- git - 是否可以为分支机构设置本地别名?
- hadoop - Hive 未与 localhost:10000 连接
- python - Python CSV解析输出不一致的计数
- android - Firebase 应用内消息在生产中不起作用
- python - 我们如何使用 decision_function(X) One-Class-SVM 计算异常分数
- ggplot2 - 增加x轴ggplot主题的线条粗细
- html - 为什么 Material Design Top App Bar 与顶部的差距很小?
- c# - 如何在单元测试中使用环境变量(.net core)
- actions-on-google - 为什么智能家居测试套件会失败?