-
Vue.js) Vue 3.0 에서 vue-session 사용하기Programing Language/Vue.js 2021. 6. 1. 14:09728x90반응형This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
///../node_modules/vue-session/index.js //수정하기 var STORAGE = null; var VueSession = { key: 'vue-session-key', flash_key: 'vue-session-flash-key', setAll: function(all){ STORAGE.setItem(VueSession.key,JSON.stringify(all)); } } VueSession.install = function(Vue, options) { if(options && 'persist' in options && options.persist) STORAGE = window.localStorage; else STORAGE = window.sessionStorage; //Vue.prototype.$session = { Vue.config.globalProperties.$session = { flash: { parent: function(){ //return Vue.prototype.$session; return this; }, get: function(key){ var all = this.parent().getAll(); var all_flash = all[VueSession.flash_key] || {}; var flash_value = all_flash[key]; this.remove(key); return flash_value; }, set: function(key, value){ var all = this.parent().getAll(); var all_flash = all[VueSession.flash_key] || {}; all_flash[key] = value; all[VueSession.flash_key] = all_flash; VueSession.setAll(all); }, remove: function(key){ var all = this.parent().getAll(); var all_flash = all[VueSession.flash_key] || {}; delete all_flash[key]; all[VueSession.flash_key] = all_flash; VueSession.setAll(all); } }, getAll: function(){ var all = JSON.parse(STORAGE.getItem(VueSession.key)); return all || {}; }, set: function(key,value){ if(key == 'session-id') return false; var all = this.getAll(); if(!('session-id' in all)){ this.start(); all = this.getAll(); } all[key] = value; VueSession.setAll(all); }, get: function(key){ var all = this.getAll(); return all[key]; }, start: function(){ var all = this.getAll(); all['session-id'] = 'sess:'+Date.now(); VueSession.setAll(all); }, renew: function(sessionId){ var all = this.getAll(); all['session-id'] = 'sess:' + sessionId; VueSession.setAll(all); }, exists: function(){ var all = this.getAll(); return 'session-id' in all; }, has: function(key){ var all = this.getAll(); return key in all; }, remove: function(key){ var all = this.getAll(); delete all[key]; VueSession.setAll(all); }, clear: function(){ var all = this.getAll(); VueSession.setAll({'session-id': all['session-id']}); }, destroy: function(){ VueSession.setAll({}); }, id: function(){ return this.get('session-id'); } } }; module.exports = VueSession; 728x90반응형'Programing Language > Vue.js' 카테고리의 다른 글
Vue.js) function 안에 function에서 this에 포함된 함수 사용하기 (0) 2021.06.01 Vue.js) vue 3.0 에서 npm install xx 이후 모듈 파일에서 Vue.prototype문법 install오류 (Cannot set property '$xx' of undefined) (0) 2021.06.01 Vue.js) 부모 자식 component끼리 데이터 주고 받기 (0) 2021.06.01 Vue.js) router-link 태그를 javscript 코드로 사용하는 방법 (0) 2021.05.28 Vue.js) 휴대폰 번호 입력 폼 maxLength 적용 시키기 (0) 2021.05.28