问题描述
如下设置,但是在浏览器地址栏不显示图标
如何设置才能显示出来
问题出现的环境背景及自己尝试过哪些方法
相关代码
link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }]
1.首先在nuxt.config.js
中配置:
link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
2.你的favicon.ico
图标文件需要放到static
目录下,结构如下图:
因此你可以检查一下你文件放的目录是否正确。
我手动把 favicon放在了项目根目录后,解决了我的问题,在nuxt项目的 server/index.js 文件里添加下面的代码,sent方法用了koa-send库;
app.use(async (ctx, next) => {
let pattern = /\.[\d\w]+$/;
let fileName = pattern.test(ctx.path)
? ctx.path
: ctx.path+'index.html';
if(ctx.url.indexOf('/dist/') > -1){
await send(
ctx,
fileName,
{root: path.join(__dirname, '../')}
)
} else if(ctx.url.indexOf("favicon.ico") > -1) {
await send(ctx, fileName, {root: path.join(__dirname, '../')})
} else {
next();
}
})
###我信你个鬼
nuxt我下载后更笨没动nuxt自己都配置好了但是就是出不来