async onSaveMaterial(params, type) {
try {
let res = await fetch('请求接口路径')
if (res.code === 0) {
alert('ok!')
}
}catch(error){
console.log(error.message)
}
}
let fetcher = axios.create({
timeout: 6000, // 设置请求超时时间6s
baseURL: baseUrl,
})
fetcher.interceptors.request.use(function (config) {
config.headers.ssotoken = storage.get('ssotoken')
config.headers.ssouid = storage.get('ssouid')
return config
}, function (error) {
return Promise.reject(error)
})
fetcher.interceptors.response.use(function (response) {
if (response.data.code === 2) {
location.href = login
}
return response.data
}, function (error) {
console.log(error.message) // 统一处理错误信息
return Promise.reject(error)
})
fetcher.post('请求路径',{参数})
.then(res => {console.log(res)})
.catch(error => { console.log(error) // 捕捉到错误信息 })