Skip to content

Commit

Permalink
๐Ÿ‘” store ์ €์žฅ ๋กœ์ง ์ถ”๊ฐ€ (#18)
Browse files Browse the repository at this point in the history
Related to: #18
  • Loading branch information
jun108059 committed Feb 20, 2023
1 parent d7dcb7e commit 047939c
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 29 deletions.
2 changes: 1 addition & 1 deletion vue/src/main.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {createApp} from "vue";
import App from "./App.vue";
import store from "./store";
import router from "@/router";
import vuetify from "./plugins/vuetify";
import Toast, {POSITION} from "vue-toastification";
import "vue-toastification/dist/index.css";
import {UpdateMedia, UploadMedia} from "vue-media-upload";
import axios from "axios";
import store from "@/store/store.js";

const options = {
position: POSITION.TOP_RIGHT,
Expand Down
7 changes: 7 additions & 0 deletions vue/src/store/getters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default {
getUserName: state => state.userName,
getToken: state => state.token,
isLogin(state) {
return state.token != null;
}
}
22 changes: 0 additions & 22 deletions vue/src/store/index.js

This file was deleted.

22 changes: 22 additions & 0 deletions vue/src/store/mutations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import router from "@/router";

export default {
setUsername(state, userName) {
state.userName = userName
},
setToken(state, token) {
state.token = token;
},
login: function (state, payload) {
state.userName = payload.name
state.token = payload.grantType + " " + payload.accessToken
},
loginCheck: function (state) {
if (!state.token) {
router.push("/login")
.catch(error => {
console.log(error)
})
}
}
}
14 changes: 14 additions & 0 deletions vue/src/store/store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {createStore} from "vuex";
import mutations from "@/store/mutations";
import getters from "@/store/getters";

const store = createStore({
state: { // ๋ณ€์ˆ˜ ์ง‘ํ•ฉ
userName: null,
token: null,
},
getters, // ๋ณ€์ˆ˜ get
mutations, // ๋ณ€์ˆ˜ set
});

export default store;
12 changes: 6 additions & 6 deletions vue/src/views/member/LoginView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
<script>
import {useToast} from "vue-toastification";
import $axiosInst from "@/common/AxiosInst"
import router from "@/router";
import store from "@/store";
export default {
setup() {
Expand Down Expand Up @@ -76,6 +74,7 @@ export default {
this.toast.success("๊ตฌํ˜„ ์˜ˆ์ •์ž…๋‹ˆ๋‹ค :D");
},
submitForm: function () {
const that = this;
if (this.validationCheck() === false) {
return false;
}
Expand All @@ -88,10 +87,11 @@ export default {
.post(url, loginForm)
.then(function (response) {
console.log(response);
const token = response.data.grantType + " " + response.data.accessToken;
console.log(token);
store.dispatch('setToken', token);
router.push("/product/list");
that.$store.commit("login", response.data);
console.log("store ์ •๋ณด : " + that.$store.getters.getUserName);
console.log("์ €์žฅ๋œ token ์ •๋ณด : " + that.$store.getters.getToken);
that.toast.info("ํ† ํฐ์ •๋ณด : " + that.$store.getters.getToken);
// router.push("/product/list");
})
.catch(function (error) {
console.log(error);
Expand Down

0 comments on commit 047939c

Please sign in to comment.