这块代码是不是多余了?
大家帮我确定下,红框内容是不是多余了,能否安全删除?
代码如下:
import request from '@/plugin/axios'
import qs from 'qs'
// import store from '@/store/index'
const store = require('@/store/index')
let commonData = {
loginType: 'R',
mchannelId: 'PIBS',
deviceType: 'PC' // 设备号
}
export function httpGet(url, params = {}) {
commonData = {
...commonData
}
let obj = {}
if (params.transCode) {
obj = {
transCode: params.transCode
}
}
return request({
url,
method: 'get',
params: {
...params,
...commonData,
...obj
}
})
}
export function httpPost(url, data = {}) {
let obj = {}
if (data.transCode) {
obj = {
transCode: data.transCode
}
}
return request({
url,
method: 'post',
headers: {
'Content-Type': 'application/json; charset=utf-8',
...commonData
},
data: {
...data,
...commonData,
...obj
},
transformRequest: [
function (data) {
return JSON.stringify(data)
}
]
})
}
export function httpForm(url, data = {}) {
let obj = {}
if (data.transCode) {
obj = {
transCode: data.transCode
}
}
return request({
url,
method: 'post',
headers: {
'Content-Type': 'application/json; charset=utf-8',
...commonData
},
data: {
...data,
...commonData,
...obj
},
transformRequest: [
function (data) {
return JSON.stringify(data)
}
]
})
}
export function httpFormConfirm(url, data = {}) {
let obj = {}
if (data.transCode) {
obj = {
transCode: data.transCode
}
}
return request({
url,
method: 'post',
headers: {
'Content-Type': 'application/json; charset=utf-8',
trsType: 'confirm',
...commonData
},
data: {
...data,
...commonData,
...obj
},
transformRequest: [
function (data) {
return JSON.stringify(data)
}
]
})
}
export function download(url, data = {}) {
return request({
url,
method: 'post',
responseType: 'blob',
data: {
...commonData,
...data
},
transformRequest: [
function (data) {
data = qs.stringify(data)
return data
}
]
})
}
export function getDownload(url, params) {
commonData = {
...commonData,
...params
}
return request({
url,
method: 'get',
responseType: 'blob',
params: {
...params,
...commonData
}
/* transformRequest: [function (data) {
data = qs.stringify(data)
return data
}] */
})
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
是否多余要看
commonData
对象里是否也有transCode
属性。看代码表达意图:
commonData
对象补充传入的对象params
/data
。transCode
属性,则不要commonData
里的同名属性覆盖。和这个同理,某种意义上来说,并没有多余
是多余了,params和data的解构已经包含transCode了,obj赋值再解构transCode完全没必要
感觉多余了,个人不能理解这样的意义
data = { transCode: null }, obj = {} // 解构的值 { transCode: null }
data = { transCode: 1 }, obj = { transCode: 1 } // 解构的值 { transCode: 1 }
data = { transCode: {} }, obj = { transCode: {} } // 解构的值 { transCode: {} }
常见的操作不是补充默认值之类的吗?