如何从资产文件夹中获取图像?
我是初学者,目前正在学习vue.js。我尝试创建一个轮播滑块,但我无法从资产文件夹中获取图像。我找不到任何解决方案,可以帮助我解决问题。谁能帮我,为什么我在网站上看不到?
<template>
<div class="container">
<div class="title">Projects</div>
<Carousel class="carousel">
<Slide v-for="(slide, index) in carouselSlide" :key="index">
<div class="slide-info">
<img :src="require(`../assets/${slide}.jpg`)" />
</div>
</Slide>
</Carousel>
</div>
</template>
<script>
import Carousel from "../utility-components/Carousel.vue";
import Slide from "../utility-components/Slide.vue";
export default {
setup() {
const carouselSlide = ["bg-1", "bg-2", "bg-3"];
return carouselSlide;
},
components: { Carousel, Slide },
};
</script>
I'm beginner and I currently learn vue.js. I try to create a carousel slider but I can't get my images from the assets folder. I don't find any solution that it helps me to solve the problem. Can anyone help me, why I don't see on the site?
<template>
<div class="container">
<div class="title">Projects</div>
<Carousel class="carousel">
<Slide v-for="(slide, index) in carouselSlide" :key="index">
<div class="slide-info">
<img :src="require(`../assets/${slide}.jpg`)" />
</div>
</Slide>
</Carousel>
</div>
</template>
<script>
import Carousel from "../utility-components/Carousel.vue";
import Slide from "../utility-components/Slide.vue";
export default {
setup() {
const carouselSlide = ["bg-1", "bg-2", "bg-3"];
return carouselSlide;
},
components: { Carousel, Slide },
};
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了解决方案。此代码(require)在vue.js 3:运行:npm run build中不存在
,您将获得DIST文件夹,可以保存图像,然后从那里拨打。它对我有用。
因此,解决方案是:
I found the solution. This code (require) doesn't exist in vue.js 3:
Run: npm run build and you'll get dist folder where you can save your images then call from there. It works for me.
So the solution is: