我希望页面记住我并在刷新后写出我保存在localStorage中的名字

问题描述 投票:0回答:1

我希望我的页面在第二次重新加载页面并写出我保存在localStorage中的名称时记住我。我已经在网上搜索了,却找不到任何东西。我现在正在按角度工作。谢谢。

angular local-storage reload
1个回答
0
投票

尝试:

// after when name is populated
localStorage.setItem('somethingUniqueName', this.name);

// when you want to read it
this.name = localStorage.getItem('somethingUniqueName');

您也可以使用非常相似的sessionStorage,但localStorage更永久。您可以研究sessionStoragelocalStorage之间的差异。

© www.soinside.com 2019 - 2024. All rights reserved.