Comments (12)
Use the
mounted
hook to bind your events, and put it inside thethis.$nextTick(() => { });
, no need for the setTimeout with a random delay.I get
TypeError: Cannot read property 'on' of undefined
when I place inmounted
usingnextTick
. If I console logthis.$refs.flickity
I can see the component.
<flickity ref="flickity"
@init="onInit"...
and then you can bind your events in onInit method
from vue-flickity.
If I wrap the event listener in a timeout I don't get the error.
setTimeout(() => {
this.$refs.flickity.on('change', (event) => {
this.$emit('change', event);
});
}, 1000);
from vue-flickity.
Try
this.$refs.flickity.on('select', function () {
console.log(vm.$refs.flickity.selectedIndex());
});
Otherwise just console.log this.$refs to see how your component is named.
This works for me with every event besides the "ready" Event. I don't see why it's not triggered, so if anybody has an idea, please let me know.
from vue-flickity.
The ready event still doesn't get triggered for me
from vue-flickity.
from vue-flickity.
setTimeout(() => { this.$refs.flickity.on('change', (event) => { this.$emit('change', event); }); }, 1000);
YEAH!!! IT WORKS!! THANKS
from vue-flickity.
Use the mounted
hook to bind your events, and put it inside the this.$nextTick(() => { });
, no need for the setTimeout with a random delay.
from vue-flickity.
Use the
mounted
hook to bind your events, and put it inside thethis.$nextTick(() => { });
, no need for the setTimeout with a random delay.
I get TypeError: Cannot read property 'on' of undefined
when I place in mounted
using nextTick
. If I console log this.$refs.flickity
I can see the component.
from vue-flickity.
That's weird. Could you create a reproduction on codesandbox? I would be interested in finding out what's causing it.
You are immediately rendering it inside a component, right?
from vue-flickity.
After starting to set this up on codesandbox I remembered that I adapted vue-flickity
into my own component (to add a few things) and in doing so I'm actually using https://github.com/metafizzy/flickity-bg-lazyload instead of the standard flickity lib.
I expect it's either a change in flickity-bg-lazyload
or perhaps something to do with a feature I added that allows me to delay the start of a carousel. Regardless of what it might be, it isn't on you to help me debug that ;)
Thanks for your suggestions so far and writing the component in the first place 🙌
from vue-flickity.
Is there a sample solution for event listening with Vue 3 & TypeScript?
from vue-flickity.
Solution for Vue 3 & Typescript event listening here
from vue-flickity.
Related Issues (20)
- Any plans to support the flickity-fullscreen option? HOT 6
- Carousel not displaying properly HOT 4
- Router links triggers during slides draggin HOT 5
- only show one pre page
- How can i instance multiple vue flickity in the same page? HOT 1
- cannot access flickity via this.$refs HOT 1
- A few methods are missing
- Open a fullscreen container with the image and comments HOT 1
- License: GPLv3 or MIT?
- Sometimes works fine, sometimes does not work properly HOT 1
- Using flickity lazyload: no effect HOT 1
- Provide API for parent component to control the destroying of Flickity HOT 1
- Cells get rendered in reverse HOT 2
- Best way to reinit HOT 1
- Request: support for imagesLoaded option HOT 2
- Fade option not working HOT 4
- Flickity + Typescript Errors: Bad Element for Flickity: .carousel HOT 1
- Images flicker when going to previous route HOT 1
- Carousel Stuck on Last Slide HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vue-flickity.