Is the Nuxt JavaScript hooks transition glitching?

Encountering a bug in Nuxt 2.4.x regarding transitions.

Here's an example from the template:

<transition
    appear //---> this never work
    v-on:before-enter="beforeEnter"
    v-on:enter="enter"
    v-on:after-enter="afterEnter"

    v-on:leave="leave">
   ....
  </transition>

Script section:

   transition: {
    mode: 'out-in',
    css: false,
    beforeEnter (el) {
      console.log('before in transition object') // works
    },
    enter (el, done) {
      console.log('enter in transition object') // works
    },
    afterEnter (el) {
      console.log('after enter in transition object') // works
    },
    leave (el, done) {
      console.log('leave in transition object') // works
      done()
    }
  },

  methods: {
    // https://nuxtjs.org/api/pages-transition
    // https://v2.vuejs.org/v2/guide/transitions.html#JavaScript-Hooks
    beforeEnter (el) {
      console.log('before in methods object') // never executed
    },
    enter (el, done) {
      console.log('enter in methods object') // never executed
    },
    afterEnter (el) {
      console.log('after enter in transition object') // never executed
    },
    leave (el, done) {
      console.log('leave in methods object') // never executed
    },
  }

If you remove all the methods in the methods object, you get these errors:

commons.app.js:9837 [Vue warn]: Property or method "beforeEnter" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://v2.vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.

found in

---> <Pages/about.vue> at pages/about.vue <Layouts/default.vue> at layouts/default.vue commons.app.js:9837 [Vue warn]: Property or method "enter" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://v2.vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.

found in

---> <Pages/about.vue> at pages/about.vue <Layouts/default.vue> at layouts/default.vue

and so on...

Any suggestions?

Answer №1

Based on the information you've provided, I have a few key points to bring to your attention.

If you take a look at the nuxt documentation here, you'll notice that the transition property is crucial in determining how the page component behaves when navigating between pages. Essentially, it controls the transitions each time you switch from one route to another.

The methods you define within the component are essentially the functions that your transition component will execute during these transitions, as explained in the vue docs here. This could explain why you're encountering an error.

It seems like your transition may not be working because you haven't defined it properly yet. Naming your transition can give you more control over its behavior, and adding CSS styling is also essential for making the transition visually effective.

https://i.sstatic.net/17Mqa.png

By referring to the chart above, you can see how pure CSS transitions smoothly move from one state to another.

I would also suggest checking out this insightful article by Sarah Drasner which delves into the topic of page transitions in depth.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Slideshow feature for showcasing images from a dynamic folder

Creating an autoslide gallery is my goal, but I'm not sure where to begin. It needs to be dynamic since the folder content will keep changing over time. Instead of manual input, I want a more automated solution. Do you have any advice or tutorials tha ...

Node.Js server not executing socket function

As a JavaScript enthusiast starting out with learning sockets through Node JS, I have encountered an issue that I can't seem to resolve. My client successfully connects to the server without any errors, but when emitting commands from the client side, ...

Quicker way to apply appendChild

Is there a more efficient method to simplify the process of creating elements from an object fetched via a request? While the current code is functional, it seems overly verbose for what appears to be a straightforward task. async function getJobs() { ...

Is it possible for me to automatically add a line break following every image that is fetched from the Flickr API?

Hello there! I'm facing a little challenge with inserting a line break after each image that loads from the Flickr API. It's tricky to manipulate the style of data that hasn't loaded in the browser yet. I've experimented with using the ...

Tips for modifying an array in initstate value with the help of useState

Struggling to update the categories array's value or insert categories json data into it after fetching from the database. Need help finding the correct way to do this. Note: Make sure to review the loadCategories function. import React, {useEffect, u ...

Using a temporary variable within a Vue loop

Currently, I am utilizing Vue along with Vuetify to create a menu containing links using the treeview component. The data source I'm working with is a nested JSON structure. The issue I am facing is regarding linking the parent "to" with its children ...

What is an alternative way to rewrite this regular expression without relying on the deprecated API?

My JavaScript code uses a regular expression, myRegexp, to match numbers in a string: var myRegexp = new RegExp('[0-9]+'); The code then extracts numbers from the string and returns an array: var string = '123:456'; var nums = []; wh ...

Step-by-step guide on utilizing bootstrap 4 modals to create a "block ui" feature - a modal screen that disables input and displays a "please wait" message

Is it possible to use Bootstrap 4 modals as a "block ui" feature to fade the screen dynamically during an AJAX call and display a "wait a minute..." message or sandglasses? Although modals in the framework can be used for UI blocking functionality, I have ...

Exploring the integration of Firebase with Next.js using getServerSideProps

I'm trying to retrieve the 'sample' document from Firestore using getServerSideProps only if a user is signed in. However, the current code I have isn't working and just returns 'can't read'. Is there a better solution or ...

Tips for adjusting the height of an iframe to ensure that all content is responsive and contained within a div set to 40% height

I am having issues with setting the height of an iframe that displays a PowerBI dashboard. My specific requirements are: The content within the iframe should be contained within a div that has a height of 40% and sets all its contents to a height of 100% ...

Remove rows that have values within a specific range

I'm facing an issue in Google Sheets where I'm attempting to delete entire rows on the "Data" sheet if any value in column B matches values from the range D3:E20 in the "Backend" sheet. The code provided works when a word is hardcoded as the cond ...

expanding a module with "module.exports" in use

I recently delved into the concept of extending a module, particularly using a functional form. I found a great resource on how to do this at . var Module = (function () { return { publicMethod: function () { // code } }; })(); Howeve ...

Resolve the infinite loop issue in Vue.js

I am attempting to verify each comment and reply made by the user, checking if the comment was posted more than 30 minutes ago in order to restrict editing capabilities. However, my current implementation is not functioning correctly and I am encountering ...

The input 'Query' cannot be matched with the type '[(options?: QueryLazyOptions<Exact<{ where?:"

Using codegen, I've created custom GraphQL hooks and types. query loadUsers($where: UserFilter) { users(where: $where) { nodes { id email firstName lastName phoneNumber } totalCount } } export functio ...

Error: The carousel in Bootstrap is throwing a TypeError because f[0] is not

We are currently utilizing Bootstrap Carousel to load dynamic slides, with each slide corresponding to an item in an array. AngularJS is employed to create the array and iterate through it. However, during execution, we encountered a javascript error Type ...

using JavaScript to send numerous text box values to various views

I have a dilemma with passing values between two views. In View1, there are text boxes for entering basic information. After the customer enters this data and clicks on 'add more details', I want to transfer these details to the text boxes in Vie ...

Succession of Mongoose queries

One interesting feature of my model is the ability to chain queries like find(), limit(), and skip(). However, there arises a question: How can I apply the limit or skip function to the output of Model.find() if the returning value does not inherently cont ...

Display Image Automatically Upon Page Opening

Currently, I have an HTML file that includes the following code: <img src="(Image from file)" alt="Raised Image" class="img-raised rounded img-fluid"> I am attempting to retrieve the image from a file when the webpage loads using the server.js file ...

What improvements can I implement to enhance the clarity and functionality of this form handler?

As a beginner working on my first Next.js app, I'm facing some challenges that seem more React-related. My app allows users to add and edit stored food items and recipes, requiring me to use multiple submit form handlers. Each handler involves: Che ...

When you click anywhere on the page, JavaScript's method __dopostback is triggered

I'm encountering an issue in my asp.net application where I have an html table. Specifically, when a user clicks on a td element within the table, I use JavaScript to store the id of that td element in a hidden field. Afterwards, I trigger __dopostbac ...