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)
If you often use FTP server in your study or work...
I have nothing to do recently, so I tinker with C...
This article shares the specific code for impleme...
1. The table tag is table, tr is row, td is cell, ...
Preface This article explains how to create a dat...
Table of contents What is cgroup Composition of c...
Table of contents 1. Scene introduction 2 Code Op...
Common points: The DIV tag and SPAN tag treat som...
Responsive design is to perform corresponding ope...
Table of contents need Get data and submit Templa...
Table of contents Packaging, launching and optimi...
1. Software Download MySQL download and installat...
CocosCreator version: 2.3.4 Most games have layer...
uninstall First, confirm whether it has been inst...
When browser vendors bend the standards and take i...