Implementation of Animations API


I seem to be often struggling with applying certain additional Ionic API’s to my codebase.
At this moment I’m trying out the basics of the new Animations API, but I cannot even get the simplest example to work.

Does anyone know what I do wrong?

   <ion-content fullscreen>
     <div ref="pages" class="pages">

<script lang="ts">
import { IonContent, IonPage, createAnimation } from '@ionic/vue'
import { ref, onMounted, defineComponent } from 'vue'
export default defineComponent({
 name: 'Editor',
 components: {
   const pages = ref()
   const animation = createAnimation()
     .fromTo('transform', 'translateX(0px)', 'translateX(100px)')
     .fromTo('opacity', '1', '0.2')    

   onMounted(() => {

   return { pages }

If you log animation.elements you should see that the array is empty. When setup is executed, the component instance has not been created yet. In other words, your ref has not been defined at the moment you create the animation.

Try moving the animation setup inside of onMounted or onIonViewDidEnter (an Ionic-specific lifecycle hook: Vue Lifecycle - Ionic Documentation)

1 Like