javascript - Unable to remove sessionStorage - Stack Overflow

Login.vue is where I set the sessionStoragesessionStorage.setItem('accessToken', response.dat

Login.vue is where I set the sessionStorage

sessionStorage.setItem('accessToken', response.data.response.accessToken)

Logout.vue is where I want to delete the sessionStorage

sessionStorage.removeItem('accessToken')

However, after logout and redirect to Login.vue, the accessToken value is still in the sessionStorage. Am I doing it wrongly ?

Login.vue is where I set the sessionStorage

sessionStorage.setItem('accessToken', response.data.response.accessToken)

Logout.vue is where I want to delete the sessionStorage

sessionStorage.removeItem('accessToken')

However, after logout and redirect to Login.vue, the accessToken value is still in the sessionStorage. Am I doing it wrongly ?

Share Improve this question asked Aug 21, 2018 at 5:34 kylaskylas 1,4656 gold badges25 silver badges41 bronze badges 3
  • "the accessToken value is still in the sessionStorage" <- how are you verifying this? – Phil Commented Aug 21, 2018 at 5:39
  • 1 How are you retrieving the access token in Login.vue? Is it possible that it's being read prior to the removeItem() call? – John Ellmore Commented Aug 21, 2018 at 5:40
  • Have you tried to remove the token by use it as follow: sessionStorage.setItem('accessToken', null)? – node_modules Commented Aug 21, 2018 at 6:37
Add a ment  | 

2 Answers 2

Reset to default 3

sessionStorage data are only accessible from the window it was created. Trying to manipulate it from another window will not work.

Consider using localStorage instead.

Use LocalStorage,

To Add Item

localStorage.setItem('accessToken', response.data.response.accessToken);

To Remove Item,

localStorage.removeItem('accessToken');

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745209291a4616742.html

相关推荐

  • javascript - Unable to remove sessionStorage - Stack Overflow

    Login.vue is where I set the sessionStoragesessionStorage.setItem('accessToken', response.dat

    9小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信