From aacc01f72b37b1dbed6f6fcadb02df729f098c0b Mon Sep 17 00:00:00 2001 From: theluyuan <1162963624@qq.com> Date: Tue, 31 Aug 2021 10:44:05 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=9F=E5=91=BD=E5=91=A8=E6=9C=9F=20?= =?UTF-8?q?=E5=B0=81=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/index.js | 40 ++++++++++++++++ src/components/st.vue | 21 ++++++++- src/main.js | 65 +------------------------- src/pages/login.vue | 103 +++++++++++++++++++++++++++++++++--------- src/router/index.js | 31 +++++++++++++ 5 files changed, 175 insertions(+), 85 deletions(-) create mode 100644 src/api/index.js create mode 100644 src/router/index.js diff --git a/src/api/index.js b/src/api/index.js new file mode 100644 index 0000000..91718e6 --- /dev/null +++ b/src/api/index.js @@ -0,0 +1,40 @@ +import axios from "axios" +import router from "../router/index.js" +// 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 +}) + +export default axios \ No newline at end of file diff --git a/src/components/st.vue b/src/components/st.vue index a796996..0450cc5 100644 --- a/src/components/st.vue +++ b/src/components/st.vue @@ -8,6 +8,24 @@