Polymer 1.x:注销后如何重设整个应用程序 [英] Polymer 1.x: How to reset entire app after logout

查看:111
本文介绍了Polymer 1.x:注销后如何重设整个应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Polymer应用程序.当用户注销时,我想将整个应用重置为原始状态. (现在,当用户注销后重新登录时,该应用会将用户返回到其注销时所处的应用状态和页面.)

I have a Polymer app. When a user logs out, I want to reset the entire app to its original state. (Right now, when the user logs back in after logging out, the app returns the user to the app state and page they were on when they logged out.)

是否有任何方便(即全球)应用程序设计或代码模式来实现此目的?如果没有方便/全局的选项,请说明如何在本地完成此操作(即在逐个元素的基础上).

Is there any convenient (i.e., global) app design or code pattern for accomplishing this? If there is nothing convenient/global, please show how to accomplish this locally (i.e., on an element-by-element basis).

经过一些研究(以及Polymer slack组中的对话),看来有两个主要建议迄今为止.欢迎其他人.

After some research (and conversations in the Polymer slack group), it looks like there are two main suggestions so far. Others are welcome.

可以使用JS语句强制刷新浏览器页面:

One can imperatively refresh the browser page using the JS statement:

location = location;

和534种其他方式.

此解决方案令我不满意.它本质上是一个 hack ,并会导致性能问题和其他不良副作用,例如等待屏幕刷新和重新绘制.

This solution is unsatisfying to me. It is essentially a hack and creates performance issues and other undesirable side effects such as waiting for the screen refresh and repaint.

有人建议使用无状态应用程序体系结构.但是我不确定如何在Polymer应用程序的编码上下文中实现它.再次欢迎提出建议和想法.

Someone has suggested using a stateless app architecture. But I'm not sure how to implement it in the coding context of a Polymer app. Again, suggestions and ideas are welcome.

推荐答案

我想出的最佳解决方案是在用户注销后使用location.reload()方法刷新浏览器.

The best solution I have come up with is to refresh the browser upon user logout using the location.reload() method.

诀窍在于,您必须为应用添加一些独特的逻辑,以防止无限循环.

The trick is you've got to add some logic unique to your app that prevents an endless loop condition.

user: {
  ...
  observer: '_userChanged',
},
...
_userChanged: function() {
  var bool = this.foo(); // Add logic here to prevent endless loop condition
  if( !this.user && bool ) {
    location.reload();
  }
},

这篇关于Polymer 1.x:注销后如何重设整个应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆