**require方法图像不使用Vuejs渲染。尽管我添加了vue-loader依赖项,并且道具正确交付。这个模板很简单-只是App组件中的一个数组,一个Parent和一个Child组件。有人能帮忙吗?
https://codesandbox.io/s/eloquent-grass-j1usw8?file=/src/components/v-旋转木马项目.vue**
- // App
- <template>
- <v-carousel :carousel_data="sliderItems" />
- </template>
- <script>
- import vCarousel from "./components/v-carousel.vue";
- export default {
- name: "App",
- data() {
- return {
- sliderItems: [
- { id: 1, name: "img1", img: "1.jpg" },
- { id: 2, name: "img2", img: "2.jpg" },
- { id: 3, name: "img3", img: "3.jpg" },
- ],
- };
- },
- components: {
- vCarousel,
- },
- };
- </script>
- //Parent
- <template>
- <div class="v-carousel"></div>
- <v-carousel-item
- v-for="item in carousel_data"
- :key="item.id"
- :item_data="item"
- />
- </template>
- <script>
- import vCarouselItem from "./v-carousel-item.vue";
- export default {
- components: {
- vCarouselItem,
- },
- props: {
- carousel_data: {
- type: Array,
- default: () => [],
- },
- },
- };
- </script>
- // Child
- <template>
- <div class="v-carousel-item">
- <img src="require('../assets/images' + item_data.img)" alt="" />
- </div>
- </template>
- <script>
- export default {
- props: {
- item_data: {
- type: Object,
- default: () => {},
- },
- },
- };
- </script>