Currently, I am tackling an issue in my VueJS project where I need to delete a topic and then smoothly scroll to the next item after the deletion process is completed.
Below is the code snippet I am using:
deleteTopic: function (index) {
var lcID="";
if(index===0) {
lcID = '#cAccordion-'+(index+1);
}
else {
lcID = '#cAccordion-'+index;
}
this.agenda.topics.splice(index, 1);
document.querySelector(lcID).scrollIntoView({ behavior: 'smooth'});
this.confirmDeleteTopicIndex = -1;
}
Everything works perfectly except for one scenario - when I try to delete the first item, I encounter the following error message: "Cannot read property 'scrollIntoView' of null."
In the code snippet provided, I have a condition to check for a zero index. While it effectively scrolls to the next item after deletion, the error persists, and I am aiming to eliminate it completely.