Answer the question
In order to leave comments, you need to log in
How to load page with scroll to specific id on Nuxt/Vue?
The essence is the following, there is an application on Nuxt, there we have categories in the form of links and each leads to routes like
'/menu/pizza',
'/menu/sushi'
etc. etc. menu/_name.vue
where name is the parameter id to which you want to scroll when loading the page. This is how it works for Tanuki , that is, when you click on the categories in the floating header, you get to the entire listing of products but with a scroll to a certain category. Answer the question
In order to leave comments, you need to log in
I solved this problem in the following way, we make the router.scrollBehavior.js file in @/app/
Then I check where the router leads, if it’s up to the route I need, then I return the object with the selector that we passed to the route params as position.
@/app/router.scrollBehavior.js
export default function(to, from, savedPosition) {
const toName = to.params.name
if (to.name === 'menu-name') {
let position = { selector: `#${ toName }` }
return position
}
}
If I understand the task correctly, try mounted on the event
this.$nextTick(function () {
//To do
})
Possible without a router
https://codesandbox.io/s/beautiful-merkle-csici
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question