vue项目中使用了axios去向后台请求数据,但是因为请求返回的then和catch要写的东西很多,而且每次请求都得写一次显得代码很冗余,所以我想复写四个方法,我只需要关心正确返回也就是res.status == 200即可,请问大伙我该怎么写?
// 复写前的axios
this.$axios({
url: `${this.$api.zhishizhongxinUrl}/workbench/newinfo/rotation`,
methods: 'get',
params: {
imageNew: 1,
num: 4,
// typeId:
}
}).then(res => {
if (res.data.code == 200) {
this.imgList = res.data.data
} else {
this.$message({
duration: 1000,
message: '新闻获取失败,错误原因:' + res.data.message,
type: 'warn'
})
}
}).catch(err => {
this.$message({
duration: 1000,
message: '新闻获取失败,错误原因:' + err,
type: 'error'
})
})