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

Make scrollBehavior work with transitions by handling a promise (fixes #1263) #1758

Merged
merged 6 commits into from
Oct 11, 2017

Conversation

homerjam
Copy link
Contributor

@homerjam homerjam commented Sep 25, 2017

As stated in the discussion in #1263 this currently works by enabling an arbitrary delay to be used within the scrollBehavior handler. A better solution would use an event handler on the router view or at least allow us to get the transition duration. Unfortunately I don't think this is possible - AFAIK we don't have access to the view from within scrollBehavior.

@homerjam
Copy link
Contributor Author

Not sure why tests are working locally but not on CI, anyone?

Copy link
Member

@blake-newman blake-newman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@homerjam just rerun the tests to ensure it was not something CI end. Looks like it is a consistent failure. Could be something to do with the test implementation.

Could you try something more specific that just a setTimeout. Perhaps use the transition API to hook into when the animation is complete. https://vuejs.org/v2/guide/transitions.html#JavaScript-Hooks

There are events you can hook into, that should give you the desired affect. https://vuejs.org/v2/api/#transition

@homerjam
Copy link
Contributor Author

homerjam commented Sep 25, 2017

Hi @blake-newman, I tracked down the test issue to me using async/await which didn't work in phantomjs.

Re. the transition API - that was one of my initial thoughts, however by my understanding we're unable to use it programatically from the scrollBehavior hook. But I think the user could maybe use it to emit an event which the scrollBehavior hook then listens for (I'm pretty new to Vue so assuming it's possible to emit/listen to events on the root/app).

@homerjam
Copy link
Contributor Author

Hey @pi0 any thoughts on this re. how it tackles nuxt/nuxt#1376?

@yyx990803
Copy link
Member

Although this does not automatically solve the transition problem, it does expose a useful async primitive for users to tackle this problem in userland.

@yyx990803 yyx990803 merged commit ce13b55 into vuejs:dev Oct 11, 2017
@hackuun
Copy link

hackuun commented Oct 12, 2017

Will it be documented, how to use this primitive?

@yyx990803
Copy link
Member

See https://router.vuejs.org/en/advanced/scroll-behavior.html at bottom

Mayvis pushed a commit to Mayvis/nana that referenced this pull request Feb 19, 2019
Fix Vue issue vuejs/vue-router#1758
Add html scroll-behavior to smooth to let scroll smoothly. (IE Safari not support this)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants