-
글쓴이글
-
2022년 8월 22일 22:41 #43651
유용환참가자강의에서 대로 로컬스토리지에 있던것을 꺼내서 보여주려고 this.$store.state.new_us = this.$store.commit('exuid', JSON.parse(localStorage.getItem('user'))) 이렇게 했는데 출력이 안되서 콘솔로 확인을 해보았더니 undefined 이렇게 나오는데 왜 정의가 되지 않은건가요 onAuthStateChanged 위에 했고 exuid(state, payload){ state.outuid = payload } => store.js outuid = '' 이렇게 하고 => store.js this.$store.state.new_us = this.$store.commit('exuid', JSON.parse(localStorage.getItem('user')))
firebase.auth().onAuthStateChanged((user)=>{ if (user) { this.$store.commit('new_users', user.uid); if (this.$store.state.new_us.length > 4){ this.$store.state.new_us = this.$store.state.new_us.substr(0, 4) localStorage.setItem('user', JSON.stringify((this.$store.state.new_us)))
} } }) 이렇게 했습니다 . this.$store.state.new_us이 정의가 안된것 같은데 왜 그런지 모르겠습니다. 로컬스토리지에는 잘 나옵니다.
2022년 8월 23일 09:55 #43684
codingapple키 마스터문자나 숫자는 JSON.parse JSON.stringify에 넣을 필요 없습니다 this.$store.state.new_us = this.$store.state.new_us.substr(0, 4) state를 직접수정하기보다는 state수정함수를 만들어사용합시다
2022년 8월 23일 11:56 #43698
유용환참가자state를 직접 수정해서 다시 새로고침 했을때 로그인한 유저의 정보가 유지 안되는건가요 JSON.parse JSON.stringify을 빼고 실행시켜도 안되네요
2022년 8월 23일 19:02 #43765
codingapple키 마스터새로고침하면 state는 초기화됩니다 새로고침시 로컬스토리지에 유저정보가 있으면 그거 store에 넣으라고 코드짜면 될듯요
2022년 8월 23일 23:39 #43799
유용환참가자if (this.$router.go()){ if(localStorage.getItem('user') != null){ this.$store.state.new_us = localStorage.getItem('user') } } 이렇게 해봤는데 실행하면 로그인을 했을때 아무런 반응이 없는데 위 코드에서 어떤것이 문제인가요
2022년 8월 24일 10:39 #43834
유용환참가자mounted() { if(localStorage.getItem('user') != null){ this.$store.commit('exuid', localStorage.getItem('user')) } }, => store.js outuid : '' exuid(state, payload){ state.outuid = payload state.new_us = state.outuid }, 결과를 보여줄때는 $store.state.new_us 사용합니다.
2022년 8월 24일 23:31 #43971
유용환참가자localStorage.setItem('user', this.$store.state.new_us) 이것도 추가했는데 새로고침하면 로컬스토리지에는 남아있는데 페이지로 볼때는 여전히 로그인이 안한상태가 됩니다. 직접 코드에 넣어보아서 왜 그런지 확인해 주실수있나요
2022년 8월 25일 09:50 #43999
codingapple키 마스터state와 로컬스토리지에 잘 저장되어있는데 페이지에서만 안나오는거면 페이지에 그것들을 출력하는 문법을 살펴보면 됩니다
-
글쓴이글
- 답변은 로그인 후 가능합니다.