하관우 하관우 04-07
2025-04-07 하관우 로그인 아이디 저장장
@799454e77044a71c5023b4d0641df672abf47590
client/views/index.js
--- client/views/index.js
+++ client/views/index.js
@@ -4,12 +4,16 @@
 import Store from "./pages/AppStore.js";
 import Router from "./pages/AppRouter.js";
 import cmmnPlugin from '@/resources/js/cmmnPlugin.js'
+import VueCookies from 'vue-cookies';
 
 async function initVueApp() {
   const vue = createApp(App)
     .use(Router)
     .use(Store)
     .use(cmmnPlugin)
+    .use(VueCookies);
+
+  vue.$cookies.config('7d'); // 쿠키의 기본 유효 기간을 1일로 설정
   vue.config.devtools = true;
   vue.mount("#root");
 }
client/views/pages/login/Login.vue
--- client/views/pages/login/Login.vue
+++ client/views/pages/login/Login.vue
@@ -15,16 +15,16 @@
             <dl>
                 <dd class="mb-25">
                     <label for="id">아이디</label>
-                    <input type="text" id="id"  placeholder="아이디를 입력하세요." v-model="member['loginId']">
+                    <input type="text" id="id" placeholder="아이디를 입력하세요." v-model="member['loginId']">
                 </dd>
 
                 <dd class="mb-10">
                     <label for="pw">비밀번호</label>
-                    <input type="password" id="pw"  placeholder="비밀번호를 입력하세요." v-model="member['password']"
+                    <input type="password" id="pw" placeholder="비밀번호를 입력하세요." v-model="member['password']"
                         @keyup.enter="fnLogin">
                 </dd>
                 <dd class="check-area flex-end mb-25">
-                    <input type="checkbox" class="margin-top">
+                    <input type="checkbox" class="margin-top" v-model="saveId">
                     <label for="save">아이디 저장</label>
                 </dd>
             </dl>
@@ -37,6 +37,7 @@
 <script>
 import { useStore } from "vuex";
 import axios from "axios";
+import VueCookies from 'vue-cookies';
 
 export default {
     data() {
@@ -46,6 +47,7 @@
             loginicon: 'client/resources/images/icon/lock.png',
             righticon: 'client/resources/images/icon/right.png',
 
+            saveId: false,
             member: {
                 loginId: null,
                 password: null,
@@ -54,6 +56,7 @@
         };
     },
     methods: {
+
         async fnLogin() {
             try {
                 const response = await axios.post("/user/login.json", this.member, {
@@ -75,6 +78,13 @@
                         this.store.commit("setLoginId", mbr.loginId);
                         this.store.commit("setUserNm", mbr.userNm);
                         this.store.commit("setRoles", mbr.roles);
+                    }
+
+                     // 아이디 저장 처리
+                     if (this.saveId) {
+                        VueCookies.set('savedLoginId', this.member.loginId, '1d'); // 1일 동안 쿠키 저장
+                    } else {
+                        VueCookies.remove('savedLoginId'); // 체크 해제 시 쿠키 삭제
                     }
 
                     // 리다이렉트 처리
@@ -102,6 +112,13 @@
     computed: {},
     components: {},
     created() { },
-    mounted() { },
+    mounted() {
+        // 페이지 로드 시 저장된 아이디 가져오기
+        const savedId = VueCookies.get('savedLoginId');
+        if (savedId) {
+            this.member.loginId = savedId;
+            this.saveId = true; // 체크박스 체크
+        }
+    },
 };
 </script>
package.json
--- package.json
+++ package.json
@@ -16,6 +16,7 @@
     "new-line": "^1.1.1",
     "swiper": "^11.2.5",
     "vue": "3.5.13",
+    "vue-cookies": "^1.8.6",
     "vue-loader": "^17.2.2",
     "vue-router": "^4.3.2",
     "vuex": "^4.1.0",
Add a comment
List