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

Getting Error in Nuxt JS "Cannot read properties of undefined (reading 'scrollTo')" #736

Open
adnanmukri opened this issue Feb 7, 2023 · 6 comments

Comments

@adnanmukri
Copy link

i am not been able to start my project whenever "npx nuxi dev" command is runned this error occurs.

@nikolashaag
Copy link

Getting the same issue on a fresh installation of Nuxt 3.

@adnanmukri
Copy link
Author

did you find any solution?

@toddpadwick
Copy link

Is this unusable for Nuxt 3 then? or has anyone found a workaround?

@adnanmukri
Copy link
Author

adnanmukri commented Apr 13, 2023 via email

@AlexanderBredun
Copy link

AlexanderBredun commented Jul 27, 2023

i have same problem but i found how to solve it, insted of using nuxt plugin from package you need to create your own for nuxt3
it goes something like this
`
import VueScrollTo from 'vue-scrollto';

export default defineNuxtPlugin((nuxtApp) => {

nuxtApp.vueApp.directive('scroll-to', {
	mounted (el, binding ) {
		const { element, duration } = binding.value;
		el.addEventListener('click', (e: Event)=> {
			e.preventDefault();
			VueScrollTo.scrollTo(element, duration, { easing: [0.12, 0, 0.39, 0] });
		});
	},
});

return {
	provide: {
		$scrollTo: VueScrollTo.scrollTo
	}
};

});`
with that we have directive and programmatic access

@ymarynych
Copy link

@AlexanderBredun thanks, your workaround seems to work!
I just adjusted several lines, since it throwed me 'undefined' for the 'element'. So, instead of
const { element, duration } = binding.value;

I say
const element = binding.value;

and then removed 'duration' from this line:

VueScrollTo.scrollTo(element, { easing: [0.12, 0, 0.39, 0] });

there's no ability to set a duration anymore, but now it works at my end. I think the problem is that 'binding.value' has wrong format or something

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants