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

examples #2

Open
719media opened this issue May 3, 2024 · 3 comments
Open

examples #2

719media opened this issue May 3, 2024 · 3 comments

Comments

@719media
Copy link

719media commented May 3, 2024

Do you have any examples of this in use with vue-router?
Is it possible to use this plugin to translate an element that exists in two different pages (e.g. an img)?

@Clarkkkk
Copy link
Owner

Clarkkkk commented May 4, 2024

Yes, it works with vue-router. We need to start the transition in beforeResolve hook:

router.beforeResolve(async () => {
  const viewTransition = startViewTransition()
  await viewTransition.captured
})

And add v-view-transition-name for the elements in both pages.

<img :src="pic" v-view-transition-name="'img'" />

Note that the parameter in v-view-transition-name should be a valid JavaScript expression, so the string must be quoted.

You can check the code in the example link in readme if you haven't checked it.

@719media
Copy link
Author

719media commented May 5, 2024

Thank you for the explanation.

What I learned was that, when using vue-router and this library, care must be taken in regards to usage of vue <Transition> with <RouterView>, a common implementation (see https://router.vuejs.org/guide/advanced/transitions). In some cases, the <Transition> will mess around with the expected results due to timing, and more specifically modes (see https://vuejs.org/guide/built-ins/transition#transition-modes).

For a quick proof of concept with this library, I found it easiest to just ensure <Transition> was not being used at all.

@Clarkkkk
Copy link
Owner

Clarkkkk commented May 7, 2024

That's interesting. When using with <Transition>, maybe we could call the startViewTransition in the transition hooks to ensure the view status is correct. And the transition hooks seems suspendible, maybe we can await the viewTransition.captured to be resolved before the transition begins. I will do some experiments later.

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

2 participants