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
Adding slides dynamically with v-for #70
Comments
Two step:
|
Thanks, that was very helpful! |
One more question though. What is the best way to remove the first (empty) slide when the state changes? |
Can you do it in your state setting? something like initial state is one dummy slide, then vuex will mutate state to your real slides? |
I'm doing something similar, yes. Problem is that That results in one extra step in the beginning, so I have to press "Next" to go to the first slide. Pasting a simplified example below (change of the state in afterMounted method, to hide Vuex complexity): Template: <slide v-for="mySlide in mySlides">
{{mySlide}}
</slide> Script: data () {
return {
mySlides: ['dummy']
}
},
methods: {
afterMounted () {
this.mySlides = ['real1', 'real2', 'real3']
setTimeout(() => {
this.findSlides()
console.log(this.slides.length) // returns 4 instead of 3
}, 10)
}
} |
That's a valid point. Sometime ago I was thinking that should be a method |
Actually, you can manually set |
Yeah, was still running into issues when I did that - having an empty slide at the beginning. Turns out that This seems to solve it for now 👍
|
If you want to do it, a PR is welcome |
@moteey could I see a code snipe of that implementation? Thanks |
|
I have a case where I need to display slides from an array with v-for.
If I have the array in component's data function, everything works fine (seems like slides are initialized when the slideshow is mounted).
However, if my array is empty when the slideshow is mounted, and later changed (via Vuex), then I get the following error:
[Vue warn]: Error in mounted hook: "TypeError: Cannot set property 'step' of undefined"
Is it possible to render slides with v-for if the data is not yet available when component is mounted?
The text was updated successfully, but these errors were encountered: