指尖上的记忆指尖上的记忆
首页
  • 基础
  • Laravel框架
  • Symfony框架
  • 基础
  • Gin框架
  • 基础
  • Spring框架
  • 命令
  • Nginx
  • Ai
  • Deploy
  • Docker
  • K8s
  • Micro
  • RabbitMQ
  • Mysql
  • PostgreSsql
  • Redis
  • MongoDb
  • Html
  • Js
  • 前端
  • 后端
  • Git
  • 知识扫盲
  • Golang
🌟 gitHub
首页
  • 基础
  • Laravel框架
  • Symfony框架
  • 基础
  • Gin框架
  • 基础
  • Spring框架
  • 命令
  • Nginx
  • Ai
  • Deploy
  • Docker
  • K8s
  • Micro
  • RabbitMQ
  • Mysql
  • PostgreSsql
  • Redis
  • MongoDb
  • Html
  • Js
  • 前端
  • 后端
  • Git
  • 知识扫盲
  • Golang
🌟 gitHub

最近做项目的时候,发现执行npx run dev 和 npx run build 结果,dev环境下土拍你资源在build后,不能访问了,研究发现是因为资源路径的问题

assets 和public 目录功能是不一样的,官方文档上有说明: Nuxt uses two directories to handle assets like stylesheets, fonts or images.

The public/ directory content is served at the server root as-is. The assets/ directory contains by convention every asset that you want the build tool (Vite or webpack) to process.

重点: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.

[官网]https://nuxt.com/docs/getting-started/assets

研究发现:

<img class="avatar" src="~/public/img/user_image.jpg" alt=""> //加了public目录以后,这个写法也可以 (直接把saaets换成public)
<img class="avatar" src="/img/user_image.jpg" alt=""> // 这个才是官方用法,就是直接访问public下的资源