I am trying to link my own custom buttons to a flickity carousel in a nuxt application. My parent component set the default value for the prop direction
to left
.
<CarouselBase class="w-screen carousel" :direction="direction">
<items/>
</CarouselBase>
data() {
return {
direction: 'left',
},
This is the code for my carousel component.
<template>
<ClientOnly>
<Flickity
ref="flickity"
:key="keyIncrementer"
class="carousel"
:class="{ 'carousel--active': active }"
:options="computedOptions"
>
<slot />
</Flickity>
</ClientOnly>
</template>
<script>
export default {
name: 'BaseCarousel',
props: {
direction: {
type: String,
default: '',
},
},
mounted() {
if (this.direction === 'right') {
this.$refs.flickity.next()
} else if (this.direction === 'left') {
this.$refs.flickity.previous()
}
},
}
I have got this file vue-flickity.js
in my plugins folder
import Vue from 'vue'
import Flickity from 'vue-flickity'
Vue.component('Flickity', Flickity)
I have got this error message =>
Cannot read properties of undefined (reading 'previous')
I don't know how to fix that...