Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- forNmae()
- 리액트
- redux
- 애그리거트
- 커스텀 로그인
- 오라클
- ACCESS_REFUSED
- REDIS
- $emit()
- .getClass()
- AWS
- 공식문서
- vue.js
- 컴포넌트 주도
- 리덕스 공식문서
- 자바
- VUE
- 네임드 뷰
- paraller
- Express
- rabbitmq 에러
- Java Reflextion API
- quert
- EBS
- exiting abnormally
- 오라클 병렬처리
- 리덕스
- react
- 자료구조
- 도커빌드
Archives
- Today
- Total
개발정리
[트러블 슈팅]로그인시 로그아웃으로 변경 본문
로그인 시에 localStorage에 토큰을 저장하는데 까진 했는데 로그인 버튼을 로그아웃으로 바꾸는 문제 해결중
24/02/05 해결
emitter를 사용해 해결했습니다.
로그인 시에 login이벤트를 발생시켜 data의 값을 변경했습니다.
<template>
<div class="header">
<div class="content">
<img src="../assets/carrot.png" />
<div>
<RouterLink to="/fleamarket"><h3>중고거래</h3></RouterLink>
</div>
</div>
<div class="inputs">
<input type="text" placeholder="물품이나 동네를 검색해보세요" style="height: 80%; width: 288px;background-color: #F2F3F6;
border:none"/>
<RouterLink to="/login"><input type="button" value="채팅하기" style="height: 80%;width: 97px; margin-right: 10px; background-color: white; "/></RouterLink>
<a v-if="hasToken"><input type="button" value="로그아웃" v-on:click="logout" style="height: 80%;width: 97px; margin-right: 10px; background-color: white;" /></a>
<RouterLink to="/login" v-else><input type="button" value="로그인" style="height: 80%;width: 97px; margin-right: 10px; background-color: white;" /></RouterLink>
</div>
</div>
</template>
<script>
export default{
data(){
return{
hasToken:false
}
},
mounted(){
this.emitter.on('login',()=>{
console.log('login!!!!!!');
this.hasToken=true;
});
if(localStorage.getItem('token')){
this.hasToken=true;
}
else{
this.hasToken=false;
}
},
methods:{
logout:function(){
localStorage.removeItem('token');
this.hasToken=false;
}
}
}
</script>
<style scoped>
.header{
width: 100vw;
min-width: 1080px;
display: flex;
justify-content: flex-start;
flex-direction: row;
position: static;
margin: 0;
}
.content{
display: flex;
justify-content: flex-start;
margin-right: auto;
}
.inputs>input{
box-sizing: content-box;
margin: 5px;
font-size: 20px;
}
a{
text-decoration: none;
color: black;
}
</style>
<template>
<div class="container">
<div class="box">
<h1 style="text-align:center">로그인</h1>
<input type="text" placeholder="아이디를 입력하세요" v-model="userId"/>
<input type="password" placeholder="패스워드를 입력하세요" v-model="password"/>
<input type="button" value="로그인" v-on:click="login"/>
<p>
아직 회원이 아니신가요?
<RouterLink to="/register"><span style="color: aqua;">회원가입</span></RouterLink>
</p>
</div>
</div>
</template>
<script>
import axios from 'axios';
export default{
data(){
return {
userId:"",
password:""
}
},
methods:{
login:function(){
const request = {
userId:this.$data.userId,
password:this.$data.password
}
axios.post("http://localhost:8080/auth/signin",request)
.then(request=>{
localStorage.setItem('token',request.data.token);
this.emitter.emit('login');
this.$router.push({ path:'/'});
});
}
}
}
</script>
<style scoped>
.container{
display: flex;
justify-content: center;
align-items: center;
height:400px;
border:1px solid black;
}
.box{
display:flex;
justify-content:center;
align-items:center;
flex-direction:column;
border:1px solid black;
padding:30px;
}
input{
box-sizing:content-box;
width:200px;
padding:0;
margin-bottom:10px;
}
</style>
'개발 > 중거거래사이트 클론' 카테고리의 다른 글
[트러블 슈팅] Cannot read properties of undefined (reading 'userId') (0) | 2024.02.23 |
---|---|
[트러블 슈팅]-라우터 params undefined 문제 (0) | 2024.02.20 |
[트러블 슈팅] jpa 양방향 매핑 조회시 stackoverflow 문제 (0) | 2024.02.18 |
[트러블 슈팅] vue.js axios 인터셉터 설정 (0) | 2024.02.16 |
[BUG] 415 (Unsupported Media) error (0) | 2024.02.03 |