Browse Source

实现登出功能

DYaiu 4 years ago
parent
commit
6eaeb50fba
2 changed files with 16 additions and 3 deletions
  1. 8 1
      src/api/login.js
  2. 8 2
      src/views/work/work.vue

+ 8 - 1
src/api/login.js

@@ -6,8 +6,15 @@ export function loginByUsername(username, password) {
         password
     }
     return request({
-        url: '/login',
+        url: '/login/',
         method: 'post',
         data
     })
+}
+
+export function logout() {
+    return request({
+        url: '/logout/',
+        method: 'post'
+    })
 }

+ 8 - 2
src/views/work/work.vue

@@ -8,12 +8,13 @@
     <child :val="val" @childByValue="childByValue" />
     <br />
     <el-button @click="login">登入</el-button>
+    <el-button @click="out">登出</el-button>
   </div>
 </template>
 
 <script>
 import child from "@/views/work/child";
-import { loginByUsername } from "@/api/login";
+import { loginByUsername, logout } from "@/api/login";
 
 export default {
   name: "work",
@@ -37,7 +38,12 @@ export default {
       this.input = chi;
     },
     login: function() {
-      loginByUsername("admin", "system");
+      // document.cookie = "csrftoken=";
+      document.cookie = "";
+      loginByUsername("linjj", "admin");
+    },
+    out: function() {
+      logout();
     }
   }
 };