Reputation: 105
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?
Upvotes: 0
Views: 1765
Reputation: 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
}
Upvotes: 1