最近在使用
Nuxt3
重构 Blog,开发过程中遇到不少问题,记录一下,遇到问题会持续更新这篇文章
安装
# npx
npx nuxi init nuxt-app
# pnpm
pnpm dlx nuxi init nuxt-app
这里大概率会被报错劝退,科学上网也不行。于是开始上网查找解决办法,试了下网上的解决办法,修改本地 hosts 文件
新增一行,185.199.108.133 raw.githubusercontent.com
然后 cmd 执行 ping raw.githubusercontent.com
可以 ping 通再执行安装命令
public 静态资源
按照原来 Nuxt2 的方式,在 assets 的目录进行图片存放,引用图片资源时发现 404 了,查阅了下文档
Nuxt won't serve files in the assets/ directory at a static URL like /assets/my-file.png. If you need a static URL, use the public/ directory.
Nuxt3 不再为 assets 目录下提供静态 URL, 那么引用图片资源 404 要放到 public 目录下
<!-- public/imgs/logo.png -->
<img src="/imgs/logo.png" alt="logo" />