question:
Problem requirement: When entering each vue page, the top of the page is displayed by default
The cause of the problem: If you do not set it, the page position displayed on the new page of Vue will default to the position previewed on the previous page, which will be very inconvenient when viewing the product details page
Solution to the problem:
Find the settings in router/index.js, add the following code, and add the location in const router = new VueRouter :
scrollBehavior(to, from, savedPosition) {
if (savedPosition) {
return savedPosition
} else {
return { x: 0, y: 0 }
}
}
Case — such as: