I am trying to convert my vue app to nuxt app. In my vue app I used vue-slick-corousel with ease. But the same code with necessary modifications for nuxt, the corousel is not working on refresh. If I edit the template real time or navigate the app without refreshing the page, it works perfectly on second time visiting the page(s). Here is how I used vue-slick-corousel in my nuxt app
//nuxt.config.js
plugins: [
{ src: './plugins/vue-slick-carousel.js' }
],
Code in the plugin js file:
//vue-slick-carousel.js
import Vue from 'vue'
import VueSlickCarousel from 'vue-slick-carousel'
Vue.component('VueSlickCarousel', VueSlickCarousel)
And finally in the template:
<!-- CustomComponent.vue -->
<template>
<div>
<VueSlickCarousel :arrows="true" :dots="true">
<div v-for="(cat, index) in categories"
:key="index"
style="height: 20px; width: 10px; background-color: red; color: white"
>
{{cat.name}}
</div>
</VueSlickCarousel>
</div>
</template>
<script>
import VueSlickCarousel from 'vue-slick-carousel'
import 'vue-slick-carousel/dist/vue-slick-carousel.css'
// optional style for arrows & dots
import 'vue-slick-carousel/dist/vue-slick-carousel-theme.css'
export default {
name: 'CustomComponent',
data() {
return {
categories: []
}
},
async fetch() {
this.categories = await fetch(
'https://*****************************/categories?limit=20'
).then(res => res.json())
},
components: {
VueSlickCarousel
},
}
</script>
This is the error I am getting on refresh "TypeError: Cannot read property 'length' of undefined"
And whenever I am rendering the page again from clientside, the error goes away. Already tried bounding the container under
<client-only>
tried using a condition
v-if="slik.length"
didn't work. How can I solve this issue?