From 9860e221460a0a4ac1903dad2c97160d0eed0e63 Mon Sep 17 00:00:00 2001
From: long <515897141@qq.com>
Date: 星期五, 03 三月 2023 10:59:42 +0800
Subject: [PATCH] 初始化

---
 src/libs/axios.js |   41 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/src/libs/axios.js b/src/libs/axios.js
new file mode 100644
index 0000000..696b55c
--- /dev/null
+++ b/src/libs/axios.js
@@ -0,0 +1,41 @@
+// axios 璇锋眰閰嶇疆
+import Axios from 'axios'
+import Config from '../config'
+
+Axios.install = (Vue) => {
+  Vue.prototype.$axios = Axios
+}
+
+// content-type 榛樿浣跨敤 form-urlencoded
+Axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
+
+// 娣诲姞璇锋眰鎷︽埅鍣�
+Axios.interceptors.request.use(function (config) {
+  // 鍦ㄥ彂閫佽姹備箣鍓嶅仛浜涗粈涔�
+  // if (!/^https?:/.test(config.url)) {
+  //   config.url = Config.domain + config.url // 鎷兼帴瀹屾暣
+  // }
+  return config
+}, function (error) {
+  // 瀵硅姹傞敊璇仛浜涗粈涔�
+  return Promise.reject(error)
+})
+// 娣诲姞鍝嶅簲鎷︽埅鍣�
+Axios.interceptors.response.use(function (response) {
+  // 瀵瑰搷搴旀暟鎹仛鐐逛粈涔�
+  // console.log(response) // 鎵撳嵃杩斿洖鐨勬暟鎹�
+  return response
+}, function (error) {
+  // 瀵瑰搷搴旈敊璇仛鐐逛粈涔�
+  // console.log(error) // 鎵撳嵃澶辫触杩斿洖鐨勬暟鎹�
+  return Promise.reject(error)
+})
+
+export default Axios
+
+// 鏍蜂緥
+// this.$axios.get('test', {} ).then((inf) => {
+//     console.log('鎴愬姛鍥炶皟')
+// }).catch((res) => {
+//     console.log('澶辫触鍥炶皟')
+// })

--
Gitblit v1.8.0