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)
need: According to business requirements, it is n...
Table of contents 1 The role of Apache 2 Apache I...
Table of contents 1. Anonymous slots 2. Named slo...
This article shares the specific code of the vue-...
1. Download, I take 8.0 as an example Download ad...
The first step is to download the free installati...
When server B (172.17.166.11) is powered on or re...
Preparation 1. Environmental Description: Operati...
Today's Tasks 1. Choice of Linux distribution...
It is very simple to build a kong cluster under t...
An index is a sorted data structure! The fields t...
Lock classification: From the granularity of data...
1. Introduction Elasticsearch is very popular now...
1. Introduction (1) Introduction to vw/vh Before ...
## 1 I'm learning docker deployment recently,...