Vue项目前端知识点整理有哪些值得收藏?

更新于
2026-10-02 11:09:43
1阅读来源:SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计2800个文字,预计阅读时间需要12分钟。

微信授权后,仍可通过浏览器返回键回到授权页。在导航守卫中,可在`next({ replace: true })`中设置`replace: true`来重定向到改路由,与`router.replace()`和`router.beforeEach()`功能相同。

微信授权后还能通过浏览器返回键回到授权页

在导航守卫中可以在 next({}) 中设置 replace: true 来重定向到改路由,跟 router.replace() 相同

router.beforeEach((to, from, next) => { if (getToken()) { ... } else { // 储存进来的地址,供授权后跳回 setUrl(to.fullPath) next({ path: '/author', replace: true }) } })

路由切换时页面不会自动回到顶部

const router = new VueRouter({ routes: [...], scrollBehavior (to, from, savedPosition) { return new Promise((resolve, reject) => { setTimeout(() => { resolve({ x: 0, y: 0 }) }, 0) }) } })

ios系统在微信浏览器input失去焦点后页面不会自动回弹

初始的解决方案是input上绑定 onblur 事件,缺点是要绑定多次,且有的input存在于第三方组件中,无法绑定事件。

后来的解决方案是全局绑定 focusin 事件,因为 focusin 事件可以冒泡,被最外层的body捕获。

阅读全文

本文共计2800个文字,预计阅读时间需要12分钟。

微信授权后,仍可通过浏览器返回键回到授权页。在导航守卫中,可在`next({ replace: true })`中设置`replace: true`来重定向到改路由,与`router.replace()`和`router.beforeEach()`功能相同。

微信授权后还能通过浏览器返回键回到授权页

在导航守卫中可以在 next({}) 中设置 replace: true 来重定向到改路由,跟 router.replace() 相同

router.beforeEach((to, from, next) => { if (getToken()) { ... } else { // 储存进来的地址,供授权后跳回 setUrl(to.fullPath) next({ path: '/author', replace: true }) } })

路由切换时页面不会自动回到顶部

const router = new VueRouter({ routes: [...], scrollBehavior (to, from, savedPosition) { return new Promise((resolve, reject) => { setTimeout(() => { resolve({ x: 0, y: 0 }) }, 0) }) } })

ios系统在微信浏览器input失去焦点后页面不会自动回弹

初始的解决方案是input上绑定 onblur 事件,缺点是要绑定多次,且有的input存在于第三方组件中,无法绑定事件。

后来的解决方案是全局绑定 focusin 事件,因为 focusin 事件可以冒泡,被最外层的body捕获。

阅读全文