From fe1b3abda89951f6e3f839e436ee58eeb3dd1ae6 Mon Sep 17 00:00:00 2001
From: theluyuan <1162963624@qq.com>
Date: Mon, 30 Aug 2021 10:26:00 +0800
Subject: [PATCH] =?UTF-8?q?=E6=8B=A6=E6=88=AA=E5=99=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main.js | 36 ++++++++++++++++++++++
src/pages/login.vue | 75 ++++++++++++++++++++++++++++++---------------
2 files changed, 87 insertions(+), 24 deletions(-)
diff --git a/src/main.js b/src/main.js
index 46f42a0..fa1d373 100644
--- a/src/main.js
+++ b/src/main.js
@@ -7,6 +7,42 @@ import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import axios from "axios"
Vue.use(ElementUI);
+// axios 全局的url前缀
+axios.defaults.baseURL = "https://tomcat.theluyuan.com/vegetables"
+// 请求拦截器 请求前修改请求的配置 可以添加token 请求头
+axios.interceptors.request.use((config)=>{
+ console.log(config)
+ // 这个请求的配置 axios({})
+ // config.url="11111"
+ // dom 添加盖板
+ // config.baseURL = "2222"
+ config.headers.token = localStorage.getItem("token")
+ return config
+})
+
+
+// 响应拦截器
+// 获取后台的信息 修改 或者 跳转页面
+axios.interceptors.response.use((res)=>{
+ console.log(JSON.stringify(res),"这是拦截器的")
+ // res.data = "这是修改之后的"
+ if(res.data.message == "请输入正确的用户信息"){
+ router.push("/index")
+ }
+ // 删除盖板
+ alert("信息")
+ return res
+})
+
+axios.interceptors.response.use((res)=>{
+ console.log("这是第二个")
+ return res
+})
+
+axios.interceptors.response.use((res)=>{
+ console.log("这是第san 个")
+ return res
+})
Vue.prototype.axios = axios
// vue 使用这个插件
Vue.use(VueRouter)
diff --git a/src/pages/login.vue b/src/pages/login.vue
index 395bc36..de1abcf 100644
--- a/src/pages/login.vue
+++ b/src/pages/login.vue
@@ -17,6 +17,15 @@
登录
+
+
+
+
+
+
+
+
+
@@ -25,28 +34,29 @@
\ No newline at end of file