From c5488b34876f863558219f998e75c798c34af3cd Mon Sep 17 00:00:00 2001 From: yangys <y_ys79@sina.com> Date: 星期二, 16 一月 2024 22:10:32 +0800 Subject: [PATCH] 修改标题错误 --- src/utils/ajax.js | 38 +++++++++++++++++++++++++++++++------- 1 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/utils/ajax.js b/src/utils/ajax.js index f17dcb3..47c823d 100644 --- a/src/utils/ajax.js +++ b/src/utils/ajax.js @@ -1,7 +1,7 @@ /* * @Date: 2022-11-09 12:37:25 * @LastEditors: Sneed - * @LastEditTime: 2024-01-05 23:41:48 + * @LastEditTime: 2024-01-12 22:39:31 * @FilePath: /belleson-frontend/Users/mache/Documents/demo/mdc/src/utils/ajax.js */ import axios from 'axios' @@ -22,12 +22,20 @@ // request鎷︽埅鍣� service.interceptors.request.use(config => { - console.log(config.url,'config') config.url = `${URL_CFG.BASE_URL}${config.url}` if (store.getters.token) { config.headers['mdc-token'] = getToken().value // 璁╂瘡涓姹傛惡甯﹁嚜瀹氫箟token 璇锋牴鎹疄闄呮儏鍐佃嚜琛屼慨鏀� } + if (config.mytype == 'json') { + config.headers = { + 'Content-Type':'application/json; charset=UTF-8' + } + } config.transformRequest = [function(data) { + // debugger + if (config.mytype == 'json') { + return JSON.stringify(data) + } return qs.stringify(data) }] return config @@ -46,11 +54,11 @@ */ const status = response.status if (status !== 200) { - Message({ - message: '鏈嶅姟杩炴帴寮傚父锛岃绋嶅悗閲嶈瘯鎴栬仈绯荤鐞嗗憳', - type: 'error', - duration: 5 * 1000 - }) + // Message({ + // message: '鏈嶅姟杩炴帴寮傚父锛岃绋嶅悗閲嶈瘯鎴栬仈绯荤鐞嗗憳', + // type: 'error', + // duration: 5 * 1000 + // }) return Promise.reject('error') } else { // const data = response.data || {} @@ -70,6 +78,13 @@ // } if (response.data.result === 'SUCCESS') { return response.data + } else { + Message({ + message: response.data.msg, + type: 'error', + duration: 3 * 1000 + }) + return Promise.reject('error') } } }, @@ -94,6 +109,15 @@ data: params }) }, + postJson: function(url, params) { + console.log(url,'url') + return service({ + mytype: 'json', + url: url, + method: 'post', + data: params + }) + }, // get璇锋眰 get: function(url, params) { return service({ -- Gitblit v1.9.3