Skip to content

Commit

Permalink
fix: ensure loadLottie is called after the component mounted (#527)
Browse files Browse the repository at this point in the history
* fix: ensure `loadLottie` invoke after `lottieAnimationContainer` is mounted

* refactor: remove unnecessary `nextTick`
  • Loading branch information
Mini-ghost authored Mar 17, 2024
1 parent d1c38f8 commit 171d54f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/vue3-lottie/src/vue3-lottie.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
defineComponent,
PropType,
watchEffect,
nextTick,
} from 'vue'
import Lottie from 'lottie-web'
import { cloneDeep, isEqual } from 'lodash-es'
Expand Down Expand Up @@ -120,6 +119,10 @@ export default defineComponent({
let direction: AnimationDirection = 1
watchEffect(async () => {
// track and ensure that `lottieAnimationContainer` is mounted
// fix: #502
if(!lottieAnimationContainer.value) return
if (props.animationLink != '') {
// fetch the animation data from the url
Expand All @@ -129,22 +132,20 @@ export default defineComponent({
const responseJSON = await response.json()
animationData.value = responseJSON
nextTick(() => loadLottie())
} catch (error) {
console.error(error)
return
}
} else if (isEqual(props.animationData, {}) === false) {
// clone the animationData to prevent it from being mutated
animationData.value = cloneDeep(props.animationData)
nextTick(() => loadLottie())
} else {
throw new Error(
'You must provide either animationLink or animationData',
)
}
loadLottie()
})
const loadLottie = () => {
Expand Down

0 comments on commit 171d54f

Please sign in to comment.