4
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

Organization

Nuxt.jsでVue carouselを使用した時に画像が読み込めない解決策

結論

  • CarouselとSlideをそれぞれ別箇にimportする

発生した問題

Guide通りにComponentをimportしてslideタグ内に画像を挿入すると
ReferenceError: document is not defined
が発生する。

<template>
    <div>
        <carousel>
            <slide>
                <img src="@/assets/image/sample1.jpeg">
            </slide>
            <slide>
                <img src="@/assets/image/sample2.jpeg">
            </slide>
        </carousel>
    </div>
</template>

<script>
import { Carousel, Slide } from 'vue-carousel';
export default {
  ...
  components: {
    Carousel,
    Slide
  }
  ...
};
</script>

解決法

Carousel・SlideそれぞれのComponentをそれぞれ別箇にimportする

<script>
import Carousel from 'vue-carousel/src/Carousel.vue'
import Slide from 'vue-carousel/src/Slide.vue'
export default {
  components: {
    Carousel,
    Slide
  }
}
</script>

Register as a new user and use Qiita more conveniently

  1. You can follow users and tags
  2. you can stock useful information
  3. You can make editorial suggestions for articles
What you can do with signing up
4
Help us understand the problem. What are the problem?