无法更改默认的 nuxt 图标

Hos*_*ein 14 javascript favicon frontend vue.js nuxt.js

我是 nuxt 的新手,并试图更改我项目中的默认图标。

我改变了favicon.pngfavicon.ico我的static文件夹中。=>没用

更改了我的文件夹中的favicon.png和。=>没用favicon.icodist

替换了我的dist/_nuxt/icons文件夹中由图标生成器网站生成的正确文件。=>没用

这是我的 nuxt.config.js

head: {
    title: "my first nuxt proj - main page",
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: pkg.description }
    ],
    link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.png' }],
  },
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?

Hos*_*ein 12

我找到了解决方案,但它有点棘手,而且离逻辑有点远。

favicon 的大小应该是32*32像素,否则 nuxt 将加载默认的 favicon 本身。

关于我的尝试,在您的static文件夹中有一个文件并提供nuxt.config.js.

但我仍然对解决方案感到困惑。

  • 我发现有一个node_modules/.cache/pwa/icon目录。我必须删除它并在 nuxt.config.js 中设置 `pwa: { source: '~/static/icon.png' },` (7认同)

Mik*_*Mik 6

您尝试过替换type: 'image/x-icon'为吗type: 'image/png'

有关此属性和标签的信息通常可以在此处阅读

nuxt 会将对象转换{ head: { link: [{ rel: 'icon', type: 'image/png', href: '/favicon.png' }] }}

<head>
  <link rel='icon' type='image/png' href='/favicon.png'>
</head>
Run Code Online (Sandbox Code Playgroud)

因此,您可以使用上面文章中列出的任何属性。