0👍
Perhaps this might be another alternative for what you’re trying to achieve:
You can use "HTML anchor links" where you set the id
attribute of the individual element you want to be scrolled to and using that id
as the value of the href attribute of their respective tab elements (LandingPage, Form, About). When a user clicks on a tab element, e.g <a href="#about">
, the window will scroll to the element with the corresponding id
. It also hashes the id of the scrolled element to the browser’s url bar, e.g https://example.io/#about
Example in code:
<nav>
<a href="#landingPage">LandingPage</a>
<a href="#form">Form</a>
<a href="#about">About</a>
</nav>
<main>
<div id="landingPage">
<!-- LandingPage Contents... -->
</div>
<div id="form">
<!-- Form Contents... -->
</div>
<div id="about">
<!-- About Contents... -->
</div>
</main>
You can throw in some smooth scrolling effect by adding the css:
* {
scroll-behavior: smooth;
}
For manually changing the url hash indicator when user scrolls to a section, you can watch for the window scroll event, and when scroll position is at position of the indicated tab section, then manually hash the id to the url bar using javascript.
- [Vuejs]-How to read OS environment variables with Vue 2.7
- [Vuejs]-How can I pass a paramater that is not contained in the url when routing to a component using Vue.js