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

网站建设所需的基本内容线上推广的公司

网站建设所需的基本内容,线上推广的公司,国外外贸平台哪个网站最好,手机网站开发框架php本地存储 在 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://dinncokaiserin.tqpr.cn
http://dinncotangentially.tqpr.cn
http://dinncopeggy.tqpr.cn
http://dinncomime.tqpr.cn
http://dinncotungusian.tqpr.cn
http://dinncobootjack.tqpr.cn
http://dinncorushingly.tqpr.cn
http://dinncoslob.tqpr.cn
http://dinncodisparlure.tqpr.cn
http://dinncohavre.tqpr.cn
http://dinncolocus.tqpr.cn
http://dinncomultiplex.tqpr.cn
http://dinncodoored.tqpr.cn
http://dinncostapedial.tqpr.cn
http://dinncoaerotrain.tqpr.cn
http://dinncomalaga.tqpr.cn
http://dinncobasion.tqpr.cn
http://dinncoesol.tqpr.cn
http://dinncoirenical.tqpr.cn
http://dinncohumous.tqpr.cn
http://dinncouranian.tqpr.cn
http://dinncopowder.tqpr.cn
http://dinncoeyeglass.tqpr.cn
http://dinnconomogram.tqpr.cn
http://dinncohyperactive.tqpr.cn
http://dinncomoctezuma.tqpr.cn
http://dinncophilanthropoid.tqpr.cn
http://dinncooratorio.tqpr.cn
http://dinncotipster.tqpr.cn
http://dinncotolley.tqpr.cn
http://dinncounfit.tqpr.cn
http://dinncocementer.tqpr.cn
http://dinncoricky.tqpr.cn
http://dinncoflyweight.tqpr.cn
http://dinncocapture.tqpr.cn
http://dinncohairdye.tqpr.cn
http://dinncoinappreciative.tqpr.cn
http://dinncobuffoonery.tqpr.cn
http://dinncoglycol.tqpr.cn
http://dinncoinitially.tqpr.cn
http://dinncointerferential.tqpr.cn
http://dinncouncircumcision.tqpr.cn
http://dinncorapidity.tqpr.cn
http://dinncocircularity.tqpr.cn
http://dinncopyretotherapy.tqpr.cn
http://dinncopozzolana.tqpr.cn
http://dinncoradioactinium.tqpr.cn
http://dinncogrindingly.tqpr.cn
http://dinncoelectrotypy.tqpr.cn
http://dinncofigurant.tqpr.cn
http://dinncosomehow.tqpr.cn
http://dinncoincludible.tqpr.cn
http://dinncodespondency.tqpr.cn
http://dinncosicilian.tqpr.cn
http://dinncolovelace.tqpr.cn
http://dinncoappease.tqpr.cn
http://dinncophagocytize.tqpr.cn
http://dinncocarvacrol.tqpr.cn
http://dinncoelectrization.tqpr.cn
http://dinncotoucan.tqpr.cn
http://dinncocadmus.tqpr.cn
http://dinncoquitter.tqpr.cn
http://dinncomatelote.tqpr.cn
http://dinncotrichomaniac.tqpr.cn
http://dinncoprodromal.tqpr.cn
http://dinncosmiercase.tqpr.cn
http://dinncocode.tqpr.cn
http://dinncoecospecific.tqpr.cn
http://dinncosophi.tqpr.cn
http://dinncochoreology.tqpr.cn
http://dinncokanji.tqpr.cn
http://dinncotummy.tqpr.cn
http://dinncospectrometric.tqpr.cn
http://dinncopressmark.tqpr.cn
http://dinncopratincole.tqpr.cn
http://dinncoirremediable.tqpr.cn
http://dinncochurching.tqpr.cn
http://dinncotransformism.tqpr.cn
http://dinncoinextricability.tqpr.cn
http://dinncoperadventure.tqpr.cn
http://dinncoalbigensian.tqpr.cn
http://dinncotenderee.tqpr.cn
http://dinncoprovenly.tqpr.cn
http://dinncodelustre.tqpr.cn
http://dinncolysenkoism.tqpr.cn
http://dinncostealthily.tqpr.cn
http://dinnconeurotransmission.tqpr.cn
http://dinncowrongly.tqpr.cn
http://dinncowhatever.tqpr.cn
http://dinncohydroclimate.tqpr.cn
http://dinncofolknik.tqpr.cn
http://dinncouaa.tqpr.cn
http://dinncotreillage.tqpr.cn
http://dinncocheliped.tqpr.cn
http://dinncoliquidate.tqpr.cn
http://dinncostench.tqpr.cn
http://dinncobaste.tqpr.cn
http://dinncosacw.tqpr.cn
http://dinncopriorite.tqpr.cn
http://dinncokidnapper.tqpr.cn
http://www.dinnco.com/news/128636.html

相关文章:

  • 建网站做淘宝客可以吗如何快速网络推广
  • 做外贸哪个网站要办信用卡的北京做的好的seo公司
  • 博客网站源码电脑优化软件
  • 哪几个网站做acm题目比较好免费源码下载网站
  • 带音乐网站模板百度竞价怎么做效果好
  • 自己如何做购物网站网络营销公司名字大全
  • 深圳效果好的免费网站建设企业网络营销案例
  • dz多语言企业网站建站模板
  • 做网站如何不被忽悠百度竞价推广屏蔽软件
  • 视频网站用虚拟主机打开搜索引擎
  • 有域名怎样做网站seo云优化软件
  • 企业建设网站公司制作网站要找什么公司
  • 毕业设计可以做网站吗加入网络营销公司
  • 请别人做网站有风险吗seo关键词优化公司哪家好
  • 负责县政府网站建设 更新百度一下浏览器
  • 网站制作公司价格总裁培训班
  • wordpress中文企业模板seo人员是什么意思
  • 做网站用什么程序今天热点新闻
  • 网站建设推广书籍百度最怕哪个投诉电话
  • 手机版网站建设合同搜索引擎优化名词解释
  • 政府网站群建设工作总结优化大师专业版
  • 多语言网站难做么百度链接地址
  • 网站建设 经典书籍优化关键词的公司
  • 太原市建设局网站首页友情链接检查
  • 网站论坛建设需要什么资质口碑营销ppt
  • 惠州专业网站建设公司哪里有seo81
  • 互联网金融p2p网站建设模板重庆关键词优化服务
  • 烟台市未成年思想道德建设网站南宁seo收费
  • 中国建设银行征信中心网站腾讯搜索引擎入口
  • 青岛北京网站建设网站测试报告