Web/HTML CSS JS

[JS] local storage / Query String

say! 2022. 10. 4. 10:35
728x90
 

Window.localStorage - Web API | MDN

localStorage** **읽기 전용 속성을 사용하면 Document 출처의 Storage 객체에 접근할 수 있습니다. 저장한 데이터는 브라우저 세션 간에 공유됩니다. localStorage는 sessionStorage와 비슷하지만, localStorage의 데

developer.mozilla.org

 

🟡 localStorage vs sessionStorage

- localStorage

도메인에 종속됨

반영구적 - 따로 지우지 않는 이상 데이터는 만료되지 않음

 

- sessionStorage

페이지를 닫을 때 데이터 사라짐

 

🔵 localStorage

- key, value 형태로 데이터 저장하기

localStorage.setItem('key', 'value')

문자데이터로 저장하기

> 자바스크립트 데이터를 문자 데이터로 변환하기

> JSON.stringify(객체)

* 반대는 JSON.parse(str)

 

- 값 가져오기

const k = localStorage.getItem('key')

 

- 데이터 삭제하기

localStorage.removeItem('key')

 

🔵 lowdb

lodash 기반으로 브라우저에 데이터 저장하고 활용할 수 있음

 

GitHub - typicode/lowdb: Simple to use local JSON database. Powered by plain JavaScript (supports Node, Electron and the browser

Simple to use local JSON database. Powered by plain JavaScript (supports Node, Electron and the browser) - GitHub - typicode/lowdb: Simple to use local JSON database. Powered by plain JavaScript (s...

github.com

 

 

🟡 Query String

주소?속성=값&속성=값

 

🔵 axios

node.js와 브라우저 환경에서도 쓸 수 있는 HTTP 요청을 처리해주는 자바스크립트 패키지

 

GitHub - axios/axios: Promise based HTTP client for the browser and node.js

Promise based HTTP client for the browser and node.js - GitHub - axios/axios: Promise based HTTP client for the browser and node.js

github.com

 

- axios 설치하는 법

npm i axios