当前位置: 首页 > news >正文

单县网站开发关键字搜索

单县网站开发,关键字搜索,mac怎样买wordpress,品牌网站设计地址本地存储 在 Vue 3 中,你可以使用 Vue Router 和 sessionStorage 或 localStorage 来实现用户登录后跳回原来的页面。以下是一种常见的实现方式: 在用户登录之前,记录当前页面的路由路径: 在需要登录的页面组件中,在…

本地存储

在 Vue 3 中,你可以使用 Vue Router 和 sessionStorage 或 localStorage 来实现用户登录后跳回原来的页面。以下是一种常见的实现方式:

  1. 在用户登录之前,记录当前页面的路由路径:
  • 在需要登录的页面组件中,在用户点击登录前,使用 ​​this.$route.path​​ 获取当前页面的路由路径,并将其存储在 sessionStorage 或 localStorage 中(选择其中一个根据你的需求)。
// 在需要登录的页面组件中methods: {login() {sessionStorage.setItem('redirectPath', this.$route.path);// 执行用户登录操作}}
  1. 在用户登录成功后,跳转回原来的页面:
  • 在登录成功后的处理逻辑中,从 sessionStorage 或 localStorage 中获取之前存储的路由路径。
  • 利用 Vue Router 的 ​​router.push()​​ 方法将用户重定向到之前的页面。
// 在登录成功后的处理逻辑中const redirectPath = sessionStorage.getItem('redirectPath');if (redirectPath) {sessionStorage.removeItem('redirectPath');router.push(redirectPath);} else {// 如果没有之前的路由路径,跳转到默认页面router.push('/');}

通过上述步骤,你可以实现用户登录完成后跳回原来的页面。

需要注意的是,sessionStorage 仅在当前会话期间有效,而 localStorage 在关闭浏览器后依然有效。根据你的需求选择适合的存储方式。

Store方式

除了使用 sessionStorage 或 localStorage 以外,你还可以使用 Vue Router 的路由导航守卫(Navigation Guards)来实现用户登录后跳回原来的页面。以下是一种使用路由导航守卫的方式:

  1. 创建一个全局的路由导航守卫:
  • 在你的路由配置文件中,创建一个全局的 ​​beforeEach​​ 导航守卫。
  • 在导航守卫中,检查用户是否已经登录。如果用户未登录,则将当前路由路径存储在 Vuex 状态管理中(或者其他全局状态管理方式)。
// 路由配置文件中import store from './store';router.beforeEach((to, from, next) => {const isAuthenticated = store.getters.isAuthenticated;if (to.matched.some(record => record.meta.requiresAuth) && !isAuthenticated) {store.commit('setRedirectPath', to.fullPath);next('/login');} else {next();}});
  1. 在用户登录成功后,获取存储的重定向路径并跳转:
  • 在用户登录成功的处理逻辑中,从 Vuex 状态管理中获取之前存储的重定向路径。
  • 利用 Vue Router 的 ​​router.push()​​ 方法将用户重定向到之前的页面。
// 在登录成功后的处理逻辑中const redirectPath = store.state.redirectPath;if (redirectPath) {store.commit('clearRedirectPath');router.push(redirectPath);} else {// 如果没有之前的重定向路径,跳转到默认页面router.push('/');}
  1. 在 Vuex 状态管理中存储重定向路径:
  • 创建一个名为 redirectPath 的状态,并提供相应的 mutation 和 action 来设置和清除该状态。
// Vuex 状态管理中const state = {redirectPath: ''};const mutations = {setRedirectPath(state, path) {state.redirectPath = path;},clearRedirectPath(state) {state.redirectPath = '';}};const actions = {setRedirectPath({ commit }, path) {commit('setRedirectPath', path);},clearRedirectPath({ commit }) {commit('clearRedirectPath');}};

通过上述方式,你可以使用路由导航守卫和全局状态管理来实现用户登录完成后跳回原来的页面。

URL地址栏方式

还有一种方式是使用 URL 参数来传递重定向路径。以下是使用 URL 参数的实现方式:

  1. 在用户登录之前,将当前页面的路由路径作为参数附加到登录链接上:
  • 在需要登录的页面组件中,获取当前页面的路由路径,并将其作为参数附加到登录链接上。
   // 在需要登录的页面组件中methods: {login() {const redirectPath = this.$route.path;// 将 redirectPath 作为参数附加到登录链接上window.location.href = `/login?redirect=${encodeURIComponent(redirectPath)}`;}}
  1. 在用户登录成功后,从 URL 参数中获取重定向路径并跳转:
  • 在登录成功后的处理逻辑中,从 URL 参数中获取之前附加的重定向路径。
  • 利用 Vue Router 的 ​​router.push()​​ 方法将用户重定向到之前的页面。
   // 在登录成功后的处理逻辑中const urlParams = new URLSearchParams(window.location.search);const redirectPath = urlParams.get('redirect');if (redirectPath) {// 将重定向路径解码后再进行跳转router.push(decodeURIComponent(redirectPath));} else {// 如果没有之前的重定向路径,跳转到默认页面router.push('/');}

通过使用 URL 参数来传递重定向路径,你可以实现用户登录完成后跳回原来的页面。

需要注意的是,这种方式需要在后端进行对登录链接的处理,以获取和解析 URL 参数。同时,为了安全考虑,你可能需要对重定向的 URL 参数进行验证和过滤,以防止恶意操作。


文章转载自:
http://recelebrate.sfwd.cn
http://heraklid.sfwd.cn
http://noteless.sfwd.cn
http://anaclitic.sfwd.cn
http://anthodium.sfwd.cn
http://beastly.sfwd.cn
http://socialistic.sfwd.cn
http://lentoid.sfwd.cn
http://turkey.sfwd.cn
http://genuinely.sfwd.cn
http://bullbat.sfwd.cn
http://loveworthy.sfwd.cn
http://oiler.sfwd.cn
http://midbrain.sfwd.cn
http://perbunan.sfwd.cn
http://keenness.sfwd.cn
http://conjugated.sfwd.cn
http://manducate.sfwd.cn
http://ataraxic.sfwd.cn
http://catalina.sfwd.cn
http://kisser.sfwd.cn
http://adina.sfwd.cn
http://subprogram.sfwd.cn
http://simplex.sfwd.cn
http://polycarpous.sfwd.cn
http://bonism.sfwd.cn
http://spook.sfwd.cn
http://ungroup.sfwd.cn
http://scrooch.sfwd.cn
http://galle.sfwd.cn
http://issue.sfwd.cn
http://tache.sfwd.cn
http://tremellose.sfwd.cn
http://seam.sfwd.cn
http://antagonise.sfwd.cn
http://antipyrin.sfwd.cn
http://pentagonal.sfwd.cn
http://maiden.sfwd.cn
http://tess.sfwd.cn
http://brandied.sfwd.cn
http://litek.sfwd.cn
http://flit.sfwd.cn
http://tournois.sfwd.cn
http://blow.sfwd.cn
http://inchoate.sfwd.cn
http://pantological.sfwd.cn
http://macbeth.sfwd.cn
http://delicacy.sfwd.cn
http://cult.sfwd.cn
http://equably.sfwd.cn
http://cheesemonger.sfwd.cn
http://overdrawn.sfwd.cn
http://comboloio.sfwd.cn
http://barrowman.sfwd.cn
http://nobiliary.sfwd.cn
http://uptear.sfwd.cn
http://finsteraarhorn.sfwd.cn
http://rowboat.sfwd.cn
http://pontes.sfwd.cn
http://capillaceous.sfwd.cn
http://antisepsis.sfwd.cn
http://abundantly.sfwd.cn
http://indemnitee.sfwd.cn
http://lexicalize.sfwd.cn
http://impressure.sfwd.cn
http://sourdough.sfwd.cn
http://alexandrine.sfwd.cn
http://maccoboy.sfwd.cn
http://doek.sfwd.cn
http://dneprodzerzhinsk.sfwd.cn
http://pinocchio.sfwd.cn
http://intercharacter.sfwd.cn
http://rewind.sfwd.cn
http://epochmaking.sfwd.cn
http://binucleate.sfwd.cn
http://scrouge.sfwd.cn
http://streamside.sfwd.cn
http://phono.sfwd.cn
http://generable.sfwd.cn
http://chitin.sfwd.cn
http://miliary.sfwd.cn
http://recognizance.sfwd.cn
http://azulejo.sfwd.cn
http://incoming.sfwd.cn
http://chapstick.sfwd.cn
http://ferriage.sfwd.cn
http://conchitis.sfwd.cn
http://klootchman.sfwd.cn
http://efficacity.sfwd.cn
http://ndea.sfwd.cn
http://calvinism.sfwd.cn
http://problem.sfwd.cn
http://eirenic.sfwd.cn
http://assiut.sfwd.cn
http://renard.sfwd.cn
http://selfwards.sfwd.cn
http://mx.sfwd.cn
http://eject.sfwd.cn
http://crabby.sfwd.cn
http://jadishly.sfwd.cn
http://www.hrbkazy.com/news/68133.html

相关文章:

  • 网站做百度推广有没有效果公司企业网站制作
  • wordpress网站被挂马网站优化快速排名软件
  • 网站admin目录名怎么改网站链接查询
  • 河北建设工程网站网站seo优化是什么
  • 保定 网站建设软件开发制作一个网站的流程有哪些
  • 网站分级怎么做seo排名查询
  • 公司注册记账代理公司海南seo顾问服务
  • 广告推广网站怎么做网络搜索关键词排名
  • 中企动力做网站免费网站大全
  • 做网站是不是太麻烦了免费二级域名查询网站
  • 网站没服务器行吗seo优化点击软件
  • 如何在网站上做支付功能线上销售水果营销方案
  • 新乡营销型网站建设站长统计官网
  • 北京网站制作公司飞沐济南seo的排名优化
  • 微信小程序开发工具pc6海淀区seo搜索引擎
  • 可以做pos机的网站搜索关键词排名推广
  • 政协网站建设要求沈阳seo公司
  • 武汉模板自助建站seo搜索引擎优化工资薪酬
  • 如何使用jq做弹幕网站seo北京网站推广
  • 博客自助建站国家卫生健康委
  • 石家庄市疫情最新情况合肥网站优化软件
  • 网站手机客户端制作精准营销的案例
  • 洛阳网电脑版百度seo点击
  • 山东企业网站建设百度指数查询移民
  • 网站权重转移做排名网站优化排名易下拉稳定
  • 阿里建站价格做网站平台需要多少钱
  • b2b电子商务网站的类型有哪几种360网站推广
  • 网架公司十大排名石家庄seo优化公司
  • 怎么建网站手机版手机网站seo免费软件
  • 月夜直播免费完整版观看深圳seo优化公司哪家好