Search code examples
vue.jsvuejs2carouselnuxt.js

How can I use images as navigation labels for Vue carousel in Vue(Nuxt)?


I am using Vue Carousel(https://github.com/SSENSE/vue-carousel). I would like to use the navigationNextLabel and navigationPrevLabel as images. Meaning, I have 2 images namely, previous_arrow.png and next_arrow.png that I want to click to slide over this carousel.

But I can't figure out how I can embed images in :navigationNextLabel and :navigationPrevLabel. This is what I have so far:

<template>
<carousel 
  :per-page="1" 
  :mouse-drag="true" 
  :navigation-enabled="true"
  :navigation-next-label="<div><img src="../assets/next_arrow.png" class="w-12 h-12" /></div>"
  :navigation-previous-label="<div><img src="../assets/previous_arrow.png" class="w-12 h-12"/></div>"
>

<slide> Slide content 1 </slide>
<slide> Slide content 2 </slide>
<slide> Slide content 3 </slide>

</carousel>
</template>

<script lang="ts">
import { Component, Prop, Vue } from 'vue-property-decorator';

@Component
export default class Gallery extends Vue {
  @Prop() 'navigationEnabled'!: string;
  @Prop() 'navigationNextLabel'!: string;
  @Prop() 'navigationPreviousLabel'!: string;
}
</script>

The error I get: 'v-bind' directives require an attribute value.

Would appreciate some help. Thanks!


Solution

  • It's possible to use CSS instead label html. Of course do not forget to hide default button html.

    .VueCarousel-navigation-button::before {
       content: "";
       position: absolute;
       top: 8px;
       height: 25px;
       width: 25px;
    }
    
    .VueCarousel-navigation-next::before {
       background: url('../assets/previous_arrow.png');
       right: 6px;
    }
    
    .VueCarousel-navigation-prev::before {
       background: url('../assets/previous_arrow.png');
       left: 6px;
    }