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

Documentation update for <script setup> #16

Closed
rhclayto opened this issue Aug 21, 2022 · 1 comment
Closed

Documentation update for <script setup> #16

rhclayto opened this issue Aug 21, 2022 · 1 comment

Comments

@rhclayto
Copy link

rhclayto commented Aug 21, 2022

Hi,

It would be useful to give an example for Vue 3 using the <script setup> pattern. I haven't yet been able to figure out how to translate the example given here with setup() to <script setup>. Specifically, how to translate

components: {
      LottieAnimation
  },

from the export.

@rhclayto
Copy link
Author

I have it working with the following config:

<script setup>
  import { onMounted, ref } from 'vue';
  // Lottie.
  import animationURL from '@/assets/animations/spinningLogo.json';
  const anim = ref(null);
  const loopComplete = () => {
    console.log('loopComplete');
  }
  const complete = () => {
    console.log('complete');
  }
  const enterFrame = () => {
    console.log('enterFrame');
  }
  onMounted(() => {
    // The DOM element will be assigned to the ref after initial render.
    anim.value.play();
  });
</script>
<template>
  <lottie-animation
    ref="anim"
     :animationData="animationURL"
     :loop="true"
    :autoPlay="false"
    @loopComplete="loopComplete"
    @complete="complete"
    @enterFrame="enterFrame"
    style="height:64px;"
  />
</template>

I had to take import LottieAnimation from 'lottie-web-vue' out of the component, otherwise it didn't work. It's already in the global scope.

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

1 participant