ming 3 yıl önce
ebeveyn
işleme
fd5555e9b6
1 değiştirilmiş dosya ile 6 ekleme ve 9 silme
  1. 6 9
      utils/http.js

+ 6 - 9
utils/http.js

@@ -12,11 +12,14 @@ const request = (method, url, data, opt) => {
 			method,
 			url: utils.isHttp(url) ? url : config.apiBaseUrl + url,
 			header: {
+				'content-type': 'application/x-www-form-urlencoded',
 				Authorization: store.state.token,
 				...opt.header
 			},
 			data
 		}).then(res => {
+			opt.showLoading && uni.hideLoading()
+			
 			const data = res.data
 			if (data.code === 201) {
 				store.commit('setUserInfo', {})
@@ -36,9 +39,8 @@ const request = (method, url, data, opt) => {
 				reject(data)
 			}
 		}).catch(err => {
-			reject(err)
-		}).finally(() => {
 			opt.showLoading && uni.hideLoading()
+			reject(err)
 		})
 	})
 }
@@ -50,16 +52,11 @@ methods.forEach(method => {
 	http[method.toLowerCase()] = (url, data, options) => {
 		const loadingTitle = method === 'GET' ? '加载中...' : '提交中...'
 		const opt = Object.assign(
-			{
-				loadingTitle,
-				header: {
-					'content-type': 'application/x-www-form-urlencoded'
-				}
-			}, 
+			{ loadingTitle }, 
 			config.httpDefaultOption, 
 			options
 		)
-		console.log(opt);
+
 		if (opt.isAuth) {
 			if (!store.state.token) {
 				// uni.navigateTo({