Aus*_*tin 4 javascript session-storage local-storage angularjs
我试图在sessionStorage中保留一些数据,但如果我刷新页面或从链接离开然后返回,则sessionStorage不再存在.
我是sessionStorage的新手,很抱歉,如果这是一个明显的修复.
基本上我将数组存储到sessionStorage中.
$scope.addPlant = function(plant) {
for (i = 0; i < $scope.userPlantList.length; i++) {
if ($scope.userPlantList[i] === plant) {
alert("You have already added this plant");
return;
}
}
$scope.userPlantList.push($scope.currentPlant);
sessionStorage.setItem("Plants",JSON.stringify($scope.userPlantList));
};
Run Code Online (Sandbox Code Playgroud)
然后,当我想看到所有存储的内容时
$scope.retreiveList = function() {
var retrieved = sessionStorage.getItem("Plants");
$scope.userPlantList = JSON.parse(retrieved);
}
Run Code Online (Sandbox Code Playgroud)
当我不刷新页面/应用程序时,这很好用.
问题:如何在刷新/立即重新访问期间让我的sessionStorage持续?
通过查看开发人员工具,检查数据是否真的消失了
如果您使用chrome:F12 - > Resources选项卡 - > Session Storage.
sessionStorage与浏览器选项卡一起使用.无论何时关闭选项卡,都会清除会话存储数据.
如果您想要在标签之间共享的内容,请查找localStorage.
| 归档时间: |
|
| 查看次数: |
13840 次 |
| 最近记录: |