vue-router常见问题解决方案。(滚轴回到顶部、页面跳转同一页面报错、手机电脑端路由跳转)
生活随笔
收集整理的這篇文章主要介紹了
vue-router常见问题解决方案。(滚轴回到顶部、页面跳转同一页面报错、手机电脑端路由跳转)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
當頁面跳轉后,側邊滾軸會還是一個頁面位置
//路由跳轉后,頁面回到頂部 router.afterEach(() => {document.body.scrollTop = 0;document.documentElement.scrollTop = 0; });頁面跳轉同一頁面,報錯
// 消除跳轉同一個頁面報錯 const originalPush = Router.prototype.push; Router.prototype.push = function push(location) {return originalPush.call(this, location).catch((err) => err); };手機、電腦端路由跳轉
const routes = [{path: '/',beforeEnter(to, from, next) {let path;if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {console.log('-----這里是移動端-----');path = '/MB';} else {console.log('-----這里是電腦端-----');path = '/PC';}next(path);},}]總結
以上是生活随笔為你收集整理的vue-router常见问题解决方案。(滚轴回到顶部、页面跳转同一页面报错、手机电脑端路由跳转)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【简易教程】基于Vue-cli使用esl
- 下一篇: python——selenium框架实现