封装axios
This commit is contained in:
@@ -536,5 +536,53 @@ export default {
|
||||
}).catch(err => {
|
||||
exeFun.call(this, err)
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
_getData (url, params, config = {}) {
|
||||
return new Promise((resolve,reject)=>{
|
||||
// 参数包含this
|
||||
let _this = config._this || false
|
||||
// 参数包含loading
|
||||
let loading = config.loading || false
|
||||
if (_this && loading) {
|
||||
_this[loading] = true
|
||||
}
|
||||
|
||||
_axios.get(api() + url + '?_t=' + new Date().getTime(), { params }).then(res => {
|
||||
resolve(res.data)
|
||||
}).catch(err => {
|
||||
reject(err)
|
||||
}).finally(()=>{
|
||||
if (_this && loading) { _this[loading] = false }
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
_postData (url, param, config = {}) {
|
||||
return new Promise((resolve,reject) => {
|
||||
var _formData = formData(param)
|
||||
// 参数包含this
|
||||
let _this = config._this || false
|
||||
// 参数包含loading
|
||||
let loading = config.loading || false
|
||||
// 是否显示操作提示
|
||||
let showTips = config.showTips === undefined ? true : config.showTips
|
||||
if (_this && loading) { _this[loading] = true }
|
||||
|
||||
_axios.post(api() + url + '?' + new Date().getTime(), _formData).then(res => {
|
||||
if (res.data.ok !== undefined && showTips) {
|
||||
let type = res.data.ok ? 'success' : 'warning'
|
||||
if (_this && res.data.message !== '' && res.data.message !== null) {
|
||||
Message[type](res.data.message)
|
||||
}
|
||||
}
|
||||
resolve(res.data)
|
||||
}).catch(err => {
|
||||
reject(err)
|
||||
}).finally(()=>{
|
||||
if (_this && loading) { _this[loading] = false }
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user