티스토리 뷰
user.js
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
import axios from 'axios'
import router from '@/router'
const state = {
context : 'http://localhost:8080/',
user : {},
auth: false,
fail: false
}
const getters = {
getMember : state=>state.user,
getIsAuth : state=>state.auth,
getFail : state=> state.fail
}
const actions = {
async login({commit}, loginData ){
const url = state.context + 'login'
const headers ={ 'authorization': 'JWT fefege..',
'Accept' : 'application/json',
'Content-Type': 'application/json'}
axios.post(url, loginData , headers )
.then(({data})=>{
if(data.result) {
commit('LOGIN_COMMIT', data)
}else{
commit('fail_commit')
}
})
.catch(()=>{
state.fail = true
})
},
async logout({commit}){
commit('LOGOUT_COMMIT')
},
async getUserInfo({commit}){
const url = state.context + 'getUserInfo'
const token = localStorage.getItem("token")
const headers = {headers : {
'Accept' : 'application/json',
}}
axios.post(url,token,headers)
.then(({data})=>{
if(data.result){
commit('REFRESH', data)
}else{
commit('LOGOUT_COMMIT')
alert(`토큰이 만료되었습니다.\n 로그인을 다시 해주세요!`)
router.push('/login')
}
})
},
async loginDestory({commit}){
commit('LOGINDESTROY')
}
}
const mutations = {
LOGIN_COMMIT(state, data){
state.auth = true
state.user = data.user
localStorage.setItem("token", data.token)
localStorage.setItem("userId",data.user.userid)
if(data.user.auth==="USER") {
router.push('/home')
}else{
router.push('/companyHome')
}
},
REFRESH(state, data){
state.auth = true
state.user = data.user
localStorage.setItem("token", data.token)
localStorage.setItem("userId",data.user.userid)
router.go(1)
},
LOGOUT_COMMIT(state){
localStorage.clear()
state.auth = false
state.user = {}
},
fail_commit(state){
state.fail = true
},
LOGINDESTROY(state){
state.fail = false
}
}
export default {
name: 'user',
namespaced: true,
state,
getters,
actions,
mutations
}
|
cs |
magazine.js
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | import axios from "axios"; const state = { context : 'http://localhost:8080/', wordList : [], originWordList : '', carsList : '', articleList : '' } const getters = { wordList : state => state.wordList, carsList : state => state.carsList, articleList : state => state.articleList } const actions = { async getExtractWord({ commit } ){ const url = state.context + 'magazine/init' axios .get(url) .then(({data})=>{ commit('GETEXTRACTEDWORD', data )}) .catch(()=>{ alert('잘못된 요청입니다.') }) }, async aiEditor({ commit } , keyWord ){ let url = state.context + 'magazine/AIEditer/'+keyWord axios .get(url) .then(({data})=>{ commit('AIEDITOR', data )}) .catch(()=>{ alert('잘못된 요청입니다.') }) }, async getSelectedWord({ commit } , targetitem ){ commit('GETSELECTEDWORD', targetitem ) } } const mutations = { GETEXTRACTEDWORD ( state , data ) { state.wordList = [] data.extractedWordList.forEach( item => { state.wordList.push([item.word , item.count]); }) }, GETSELECTEDWORD ( state , targetitem ) { state.originWordList = state.wordList state.wordList = [] state.wordList.push(targetitem) }, AIEDITOR ( state , data ) { state.carsList = [] state.articleList = [] state.carsList = data.carsList state.articleList = data.articles } } export default { name: 'magazine', namespaced: true, state, getters, actions, mutations } | cs |
'3. 스크립트' 카테고리의 다른 글
TS/VS코드/2020-06-21/ TS tsconfig.json 의 여러 예제 (0) | 2020.06.21 |
---|---|
[자바스크립트] "자바마저 제쳤다" 자바스크립트, 인기 언어 1위 (0) | 2020.06.18 |
[VueJS] 에러 : cannot read property 'dispatch' of undefined in Vuex (0142:20) (0) | 2020.05.25 |
[뷰JS] 커맨드에서 설정하기 ( 뷰js 4.x 버전 이후 반영) #40 (0) | 2020.05.25 |
(타슈켄트) 뷰> Spring Boot 에서 Vue.js 설정하기 (0) | 2020.05.25 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- mariadb
- maven
- terms
- springMVC
- Django
- ERD
- docker
- Mlearn
- COLAB
- vscode
- nodejs
- JUnit
- intellij
- Git
- Algorithm
- tensorflow
- Mongo
- AWS
- KAFKA
- Java
- SpringBoot
- Python
- JPA
- Oracle
- Eclipse
- FLASK
- database
- React
- jQuery
- SQLAlchemy
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함