Is there a way to programmatically scroll the page in Vue?

Question from a newbie:

I want the page to automatically scroll to the bottom once it's fully loaded. Can someone help me with this?

This is the JavaScript code I'm struggling to integrate into Vue:

let scrollToBottom = () => {
    window.scrollTo(0, document.body.scrollHeight);
}

window.addEventListener("load", scrollToBottom);

Answer №1

If you're working with Vue, the mounted function is triggered once the page or component has fully loaded. You can utilize this function to execute certain actions like so...

Vue.config.devtools = false
Vue.config.productionTip = false

new Vue({
 el: '#app',
 mounted: function() {
    window.scrollTo({ top:document.body.scrollHeight, behavior: 'smooth'});
 }
})
#scrooll {
  height: 1900px;
  border: 1px solid red;
}

#scrooll h1 {
position:absolute;
top: 1800px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<div id="scrooll">
  <h1>Hey I shoud be at bottom</h1>
</div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

A guide on navigating to a different component in Vuejs using a link

<div class="enterprise-details" style="margin-top: 20px"> Already signed up? <a href="#"> LOGIN</a></div> <!-- Component for redirection --> <b-button v-if="!registeredUser" class="button-self" v-b-modal.modal-x>Lo ...

Create a basic cache within an AngularJS service to store data retrieved from HTTP requests, ensuring that the cache returns an object

Looking to implement a simple caching mechanism in an AngularJS service for data retrieved from HTTP requests. The goal is to always reference the same object to avoid duplicating requests. Below is an example code snippet showcasing the issue at hand. Li ...

The issue of loading SVG with textureloader in three.js has been reported not to work properly since version

I've had success using svg files with Three.js versions R76 and R77, but now in R78 I can only get it to work with pngs and jpgs var floor = new THREE.TextureLoader(); floor.load('layout.svg', function ( texture ) { var geom ...

What is the best way to update data in Highcharts with Vue 3?

Issue with Updating Highcharts Data Using Vue.js 3 Within my Vue.js 3 web application, I have integrated a Highcharts Chart alongside some statistics display. This setup includes global buttons for time-filtering options such as All, Year, Month, and Week ...

Firebase integration for tracking leaderboard positions

Currently, I have a project where I need to showcase a leaderboard featuring the top 20 users, with those not included still appearing in 21st place alongside their current ranking. I'm looking for an efficient way to accomplish this task. My databas ...

Flex items refusing to wrap in a flexbox with a column-direction orientation

In my code, I am using an outerWrapper, innerWrapper, and children. The outerWrapper has a fixed height of 300px and is styled with display: flex. Similarly, the innerWrapper also has a style of display: flex with flex-direction: column. However, when I a ...

Generating numerous responses in Node (sails js) from a solitary function

Currently, I am facing an issue while developing a web application using AngularJS and Sails. The problem arises in my application's menu section where different count values are supposed to be displayed from the database. When I try to retrieve this ...

Prevent any additional input[file] options from being enabled until the initial selection of the first file (#1)

I am facing an issue with file uploads where I have multiple input fields and I am attempting to use jQuery to disable all except the first one (file #1). Once the first file is selected, I want to enable the rest of the inputs. Here is my code: <i ...

Unlock the tab element within a modal using ng-bootstrap

I am currently encountering an issue with ng-bootstrap in Angular 2. I am unable to access the #tabs variable from my component using @ViewChild. This problem arises only when I utilize the tab directive within the modal directive. Here is a snippet of m ...

Clone the "big" div element and insert data within it

Is there a way to dynamically generate div elements while looping through a JSON array? I have various data items that I need to display in separate thumbnails within a row. I am looking for a template structure like the following: for(var i = 0; i < ...

Creating a hyperlink in VueJS with a method

I am currently learning Vue2 and I am working on developing a function that can replace text in a string with a hyperlink. The specific task at hand is to turn the text in parentheses into a hyperlink (LINK 22). The hyperlink should direct to . To achie ...

Tips for retrieving and transferring the device key during social login with Cognito and AWS Amplify

I am working on integrating Cognito's setDeviceStatusRemembered function into the social login process, but I am facing an issue with the deviceKey parameter. The user object returned does not contain the required deviceKey. This project is built usi ...

Sending files and attributes to a controller in ASP.NET MVC in order to retrieve a dynamically generated PDF as a Binary response - here's how!

I've been struggling with this issue for a few days now and I just can't seem to figure it out. The task at hand is to call an action that requires two pictures and three strings as parameters. This function will use iTextSharp to generate a PDF ...

Can child components forward specific events to their parent component?

I created a basic component that triggers events whenever a button is clicked. InnerComponent.vue <template> <v-btn @click="emit('something-happened')">Click me</v-btn> </template> <script setup lang=" ...

Symfony along with React router have encountered an error: route not found

In my current project, I am working with Symfony3 and integrating React.js along with react-router to create a bundle. One issue I have encountered is that when using the routing in React, if I refresh the page, the Symfony routing module displays 'N ...

Generate the entity and then transfer the data into an array

I am dealing with multi-level hierarchies that need to be displayed in a select list. Once the user selects values from the table column, they should be able to filter by clicking on the column. var name = ['Akansha', 'Navya']; var age ...

Calendar control failing to trigger the OnTextChanged event in the textbox

I have integrated a calendar control from the internet for phone use, where users can scroll up and down to select a date and time before clicking 'Confirm' or 'Cancel'. However, I am not familiar with JavaScript. The relevant JavaScrip ...

Replacing default hover behavior from an external library

Currently, I am utilizing a JS library that comes with a specific widget. Basically, I have the following list (I removed unnecessary DOM code): <li class="disabled"> When I hover over this list item, it turns into: <li class="disabled state-a ...

What is the reason behind Node's error callback returning undefined first?

Whenever I try to run the error callback function, the code below returns undefined. I'm puzzled by why the JSON isn't being returned when the console log displays the entire query. Take a look at the function that is triggering the json to be l ...

Feature for jotting down notes, creating a break between lines without any information present

I'm currently working on implementing a note-taking feature for my web application. However, I have encountered two issues: Firstly, I am struggling to identify line breaks within the text. While I can hardcode text with line breaks, when a user clic ...