Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

157
Vistas
Flickity carousel doesn't work on load but start working when user resizes the window in a vue and rails application

I am using a Flickity carousel in a vue (frontend) ruby on rails (backend) application. When my app loads the items in my carousel display vertically, as if the carousel didn't even exist. If I resize my window, then the carousel kicks in (behaves like a carousel).

<template>
  <Flickity ref="flickity" :key="keyIncrementer" :options="computedOptions">
    <item1 />
    <item2 />
    <item3 />
  </Flickity>
</template>

<script>
import Flickity from "vue-flickity";
import { debounce } from "lodash";

const DEFAULT_OPTIONS = {
  cellAlign: "left",
  pageDots: false,
  prevNextButtons: true,
};
export default {
  components: {
    Flickity,
  },

  props: {
    options: {
      type: Object,
      required: false,
      default: () => ({}),
    },
  },
  data() {
    return {
      keyIncrementer: 0,
    };
  },
  computed: {
    computedOptions() {
      return { ...DEFAULT_OPTIONS, ...this.options };
    },
  },
  created() {
    this.$root.$on("refresh-carousel", this.refresh);
  },
  mounted() {
    this.refresh();
    window.addEventListener("resize", this.debounceRefresh);
  },
  beforeDestroy() {
    window.removeEventListener("resize", this.debounceRefresh);
  },
  methods: {
    debounceRefresh: debounce(function () {
      this.refresh();
    }, 100),
    refresh() {
      this.$nextTick(() => {
        this.keyIncrementer++;
      });
    },
  },
};
</script>

If anyone knows why this is happening, that would help. I would like to have a carousel as soon as the component mounts, without resizing.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda