Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to run Resize on load? #37

Open
p3lican opened this issue Jun 26, 2018 · 8 comments
Open

How to run Resize on load? #37

p3lican opened this issue Jun 26, 2018 · 8 comments

Comments

@p3lican
Copy link

p3lican commented Jun 26, 2018

Hoping someone can help with this issue.

methods: {
    resize() {
      this.$refs.flickity.resize()
    }
  },

  beforeMount() {
    this.resize()
  }

This is not working. I'm getting:
[Vue warn]: Error in beforeMount hook: "TypeError: Cannot read property 'resize' of undefined"

if I use mounted() I don't get an error but the slides aren't resized.

If I put it in a button, resize works on click:
<button @click="resize()">Resize That

@OriginalEXE
Copy link

Maybe try this:

methods: {
  resize () {
    this.$refs.flickity.resize()
  }
},

mounted () {
  this.$nextTick(() => {
    this.resize()
  })
}

@p3lican
Copy link
Author

p3lican commented Jul 3, 2018

Thanks a lot for the reply. Unfortunately nothing changes on my end.
I put a console.log below the nextTick just to make sure it was being fired and I did see the console.log.

methods: {
    resize() {
      this.$refs.flickity.resize();
    },
  },
 mounted () {
    this.$nextTick(() => {
      this.resize()
    })
      console.log("This.resize was fired but did nothing")
  },

@bardiaabasirad
Copy link

Any solution for this problem?

@bardiaabasirad
Copy link

Any solution for this problem?

I use setTimeout with 1 second but it not a good idea!

resize() { setTimeout(() => { this.$refs.flickity.resize(); },1000); }

@EnzoBatista
Copy link

Use this.$refs.flickity.rerender(); instead of this.$refs.flickity.resize();

works for me ;)

@emdahlstrom
Copy link

@EnzoBatista Hm, interesting! That doesn't work for me, I can't seem to find this rerender() method in the flickity api or on the flickity object. Can you tell us a bit more?

@EnzoBatista
Copy link

EnzoBatista commented Aug 30, 2019

@emdahlstrom Dude, i've used rerender() method in nuxt like this this.$refs.flickity.rerender();, but i think it's available in react js too and in some way you can do this in vue js

@mihalidis
Copy link

mihalidis commented Aug 19, 2021

Use this.$refs.flickity.rerender(); instead of this.$refs.flickity.resize();

works for me ;)

Not work for me now :/ we're using SSR btw maybe that's why didn't work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants