gpt4 book ai didi

How to point to an Image source after compiler changes the file name?(编译器更改文件名后如何指向图像源?)

转载 作者:bug小助手 更新时间:2023-10-25 16:36:45 26 4
gpt4 key购买 nike



I want to load images from some folder (assets\png\slidingImage\SlidingImage_3.png) and then on click or after X seconds, it should go to the next image. I tried to change ...SlidingImage""""_3"""".p... this part into """"_4"""" and change images one after the other. The problem is Parcel renames images to SlidingImage_3.SOME_NUMBERS.png and these numbers are unique for every image.
Q1: How do I point to an image after Pacrel "compiles" them (if that's the term)?
Q2: How do I set Img src only with typescript without going through, How is that done in big projects?

我想从某个文件夹(Assets\PNG\SlidingImage\SlidingImage_3.png)加载图像,然后单击或在X秒后,它应该会转到下一个图像。我尝试更改...SlidingImage“_3”.p...此部分变为“_4”,并一个接一个地变换图像。问题是Parcel将图像重命名为SlidingImage_3.SOME_NUMBERS.png,并且这些数字对于每个图像都是唯一的。问题1:在Pacrel“编译”了一张图片后,我该如何指出它们(如果这是一个术语)?问题2:我如何在不通过的情况下只用类型脚本设置img src,在大型项目中是如何做到的?



#changeImage() {
let oldURL: string = this.#slidingImage?.getAttribute(`src`) as string;

const newURL = oldURL?.replace(`_${this.#oldActiveDot?.getAttribute('data-dot')}`, `_${this.#activeDot?.getAttribute('data-dot')}`);

this.#slidingImage?.setAttribute('src', oldURL);

}

This does the job of replaceing the number in the URL based on which dot is active, but those random numbers are added without my consent :S.

这将根据哪个点是活动的来替换URL中的数字,但这些随机数字是在未经我同意的情况下添加的:S。


enter image description here
o
This is logged image URL.

O这是记录的图像URL。


Q3: Is there a way to point to a 1st or specific file in some folder (even after the compiler munches them together? To find a file based on something in the name?

Q3:有没有一种方法可以指向某个文件夹中的第一个或特定的文件(即使在编译器将它们咀嚼在一起之后?根据名称中的某些内容来查找文件?


Thanks in advance, random helper!

谢谢你的帮助,随机的帮助!


更多回答

Well, I didn't know until now, but yes. Is it possible to do that and are there any other ways to refer to the image name with hash before it gets compiled and get's that unique hash?

嗯,我直到现在才知道,但是的。有可能做到这一点吗?有没有其他方法可以在编译并获得唯一的哈希之前使用哈希引用映像名称?

What you sent me is exactly that, but I get an error "bundles must have unique name." so I cant find a way to add that.

您发送给我的就是这样,但我得到了一个错误:“捆绑包必须有唯一的名称。”所以我找不到一种方法来添加它。

Thank You. I managed to find a workaround. I added class to all images and just looped throw them (adding and removing the "hidden" class). Not the best solution for bigger examples of this I assume, so I'm still on a hunt for a better soliton :>.

谢谢。我设法找到了一种变通办法。我向所有图像添加了类,然后循环抛出它们(添加和删除“隐藏”类)。我想对于更大的例子来说,这不是最好的解决方案,所以我仍然在寻找更好的孤子:>。

I do believe you might need a webpack's require.context().

我相信你可能需要一个webpack的require.context()。

优秀答案推荐
更多回答

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com