[英]closing and opening live-server for an app deletes my local storage
I wrote some basic 'To-do' app in JavaScript and HTML, for some reason local storage is deleting after I close and re-open the live-server in terminal.我在 JavaScript 和 HTML 中编写了一些基本的“待办事项”应用程序,由于某种原因,在我关闭并重新打开终端中的实时服务器后,本地存储正在删除。 when i refresh or even close browser and re opens it, everything works just fine.
当我刷新甚至关闭浏览器并重新打开它时,一切正常。
just when I close the live-server and re opens it and enters to the browser app, all local storage gone and i start fresh (which is only an array of objects called 'todos')就在我关闭实时服务器并重新打开它并进入浏览器应用程序时,所有本地存储都消失了,我重新开始(这只是一个名为“todos”的对象数组)
While using the app the local storage items are created perfectly and saved perfectly.在使用该应用程序时,本地存储项目被完美创建并完美保存。
this is how I wrote my getSavedTodos (from local storage) and the saveToStorage functions:这就是我编写 getSavedTodos(来自本地存储)和 saveToStorage 函数的方式:
// Fetch existing todos from localStorage
const getSavedTodos= () => {
const todosJSON= localStorage.getItem('todos')
if(todosJSON !== null)
{
return (JSON.parse(todosJSON))
}
else
{
return []
}
}
//save todos to storage
const saveDataToStorage= (todos) =>
{
localStorage.setItem('todos', JSON.stringify(todos))
}
what am I missing?我错过了什么?
this is my terminal这是我的终端
na:~/Desktop/js/apps$ live-server todo-app
http://0.0.0.0:8080 is already in use. Trying another port.
Ready for changes
Serving "todo-app" at http://127.0.0.1:41709
GET /favicon.ico 404 1.473 ms - 150
^C
na:~/Desktop/js/apps$ live-server todo-app
http://0.0.0.0:8080 is already in use. Trying another port.
Ready for changes
Serving "todo-app" at http://127.0.0.1:38307
GET /favicon.ico 404 2.197 ms - 150
Change detected todo-app/todo-functions.js
The port that is taken (8080) is another app im working on.占用的端口(8080)是我正在开发的另一个应用程序。
Thank you very much!非常感谢!
LocalStorage is unique per origin. LocalStorage 每个来源都是唯一的。 You have to make sure the server always run on same port.
您必须确保服务器始终在同一端口上运行。
You can close the app running on 8080. Or simple run the app on another port:您可以关闭在 8080 上运行的应用程序。或者简单地在另一个端口上运行应用程序:
live-server todo-app --port=8081
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.