5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Last updated at Posted at 2018-06-06

結論

  • 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>
5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?