0

I am facing problem scrolling page to a div on page load using vue js.

<div v-for="(answer, index) in answers">
    <p>{{answer.id}}</p> <p>{{answer.body}}</p>
</div>

how can i scroll page onload to answer having certain id?

1 Answer 1

1

Try to add a ref to each div like :

<div v-for="(answer, index) in answers" :ref="answer.id">
    <p>{{answer.id}}</p> <p>{{answer.body}}</p>
</div>

and in mounted hook add the following code :

mounted(){
 this.$refs["4"].scrollIntoView({behavior: "smooth", block: "start", inline: "start"});
  //replace 4 by your preferred id

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.