Overall EffectWhen you scroll through the homepage list and enter the details page, you can return to the previously browsed location when you switch back to the homepage. Listen for container scroll eventsDefine a scroll event and bind it to the container's scroll event. I've done some throttling here. const savePosY = () => { if(state.timer) return; state.timer = setTimeout(() => { let node = document.querySelector(".contentWrapper"); //Record scroll positionstore.commit("setY",node.scrollTop) state.timer = null; clearTimeout(state.timer); },100) Get the container in mounted to bind the event onMounted(() => { let contentWrapper = document.querySelector(".contentWrapper"); contentWrapper.addEventListener("scroll",savePosY); }) Configuration in the store
export default { state:{ y:0 }, mutations: setY(state,value){ state.y = value; } } } Get the scroll position when the page jumps backAlso operate in onMounted, otherwise the container element cannot be obtained, and because DOM in Vue is rendered asynchronously, we need to operate in nextTick to be effective at lastThe above is the full content of this article. If there is something wrong or a better method, you are welcome to communicate and point it out. The above is the details of the example of how vue3 uses store to record the scroll position. For more information about vue to record the scroll position, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: How to solve the error "ERROR 1045 (28000)" when logging in to MySQL
>>: How to view and clean up Docker container logs (tested and effective)
Preface Today I encountered a very strange proble...
Insert image tag <IMG> The colorful web page...
1. VMware download and install Link: https://www....
Preface When we deploy applications to servers as...
In this blog, we will discuss ten performance set...
Table of contents Hidden, descending, and functio...
Table of contents vue2.x Pre-concept: Routing hoo...
Prepare: MySQL 8.0 Windows zip package download a...
Why do we need master-slave replication? 1. In a ...
Today I helped a classmate solve a problem - Tomc...
Table of contents 1. Problem scenario 2. Cause An...
Table of contents Brief Analysis of MySQL Master-...
Today I received a disk alarm exception. The 50G ...
Network security is a very important topic, and t...
When learning kubernetes, we need to practice in ...