--- title: Vue 將參數儲存在用戶端(sessionStorage、localStorage) tags: Vue.js, sessionStorage, sessionStorage description: Vue 將參數儲存在用戶端(sessionStorage、localStorage) --- # Vue 將參數儲存在用戶端(sessionStorage、localStorage) ## seession storage 將參數儲存在用戶端 在瀏覽器關掉之後參數就會被清除 ### setItem儲存參數 ``` var name = "qct" sessionStorage.setItem("userName", name) ``` ### getItem取得參數 ``` sessionStorage.getItem("userName") // qct ``` ### removeItem 移除參數 ``` sessionStorage.removeItem("userName") ```` --- ## local storage 將參數儲存在用戶端 * 參數不會過期除非手動清除 * 預設大小5MB ### setItem儲存參數 ``` var name = "qct" localStorage.setItem("userName", name) ``` ### getItem取得參數 ``` localStorage.getItem("userName") // qct ``` ### removeItem 移除參數 ``` localStorage.removeItem("userName") ```` ### clear 移除全部參數 ``` localStorage.clear() ```` --- ## Thank you! :dash: You can find me on - GitHub: https://github.com/shaung08 - Email: a2369875@gmail.com
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up