VUE资产图像URL自动更改

发布于 2025-02-05 04:16:21 字数 389 浏览 2 评论 0原文

我将获得我在VUE项目中使用的图像,作为另一个项目的URL。当我这样称呼它时,Vue一侧没问题:

    <v-img
      class="header__logo"
      lazy-src="@/assets/images/mail.jpg"
      src="@/assets/images/mail.jpg"
      alt="Logo"
    ></v-img>

当我从浏览器中查看URL时,我看到已添加了大胆标记的位置,并且我看到每次发布时都会更改此代码。

http:// localhost:8081/img/mail。 3D6D7034 .jpg

我如何设置此设置以不更改?

I will get an image that I use in Vue project as url from another project. No problem on vue side when I call it like this :

    <v-img
      class="header__logo"
      lazy-src="@/assets/images/mail.jpg"
      src="@/assets/images/mail.jpg"
      alt="Logo"
    ></v-img>

When I look at the url from the browser, I see that the place marked in bold has been added and I see that this code changes every time we release.

http://localhost:8081/img/mail.3d6d7034.jpg

How can I set this to not change?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你的他你的她 2025-02-12 04:16:21

我的资产文件名称是什么?

Assets 在Vue-Cli/Nuxt 2项目中使用WebPack 捆绑(更具体地说, Asset-Module 。这意味着它们被包含在代码块中,以减少HTTP请求和大小。

阅读有关 Assets的文档,请阅读vue-cli文档。

在捆绑时, WebPack模块还包括放射的文件名中的哈希。这就是为什么该部分在每个构建中都会改变的原因。

解决方案:如果您需要此映像文件具有静态名称,则可以将其包含在 public/文件夹中。
它不会通过webpack,并且不会更改其名称。这样做的缺点是您必须使用文件的绝对路径,它使用@/assets /....不再相对。

阅读有关 public public folder 。


What is that hash in my asset file name?

Assets in a vue-cli / nuxt 2 project are bundled using webpack (more specifically the asset-module. That means they are included into a code chunk to reduce http requests and size.

Read vue-cli documentation about assets.

While bundling, the webpack module also includes a hash into the emitted file name. That's why this part changes over every build.

Solution: If you require this image file to have a static name, you can include it into your public/ folder instead.
It won't go through webpack, and its name will not be altered. The downside of this is that you have to use the absolute path of the file, it's not longer relative using @/assets/....

Read about the public folder.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文