Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

158
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda