1、安装
npm i axios
2、引入
import axios from 'axios';
3、interceptors代码
//headers加参数
axios.interceptors.request.use(config => {
config.headers.common["Authorization"] = token
return config;
});
//响应拦截器即异常处理
axios.interceptors.response.use((response, config) => {
//请求成功
if (response && response.data.code == 10000 || response.data.code == 1) {
return response
} else {
Message.warning({ message: response.data.message });
return Promise.reject(response);
}
//请求失败
}, err => {
if (err && err.response) {
switch (err.response.status) {
case 401:
Message({
type: "error",
message: err.response.data.Message
});
window.location.href = '/login'
break;
default:
Message({
type: "error",
message: err.response.data.Message
});
}
} else {
Message({
type: "error",
message: '服务器出错,请联系管理员!'
});
}
return Promise.resolve(err.response)
});
vue安装axios脚手架报“ ./node_modules/axios/lib/core/mergeConfig.js”错误解决方法
vuejs打包后修改static文件夹下json文件中值但页面上获取不到最新数据
上面是“vue-axios interceptors(拦截器)方法介绍”的全面内容,想了解更多关于 vuejs 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_2168.html
workflows工作流
一只黑色的小猫在童话森林里嗅着一朵发光的外星花
一只开屏的白色孔雀ComfyUI工作流
沙漠里一只红黑相间的蝎子
一个闪闪发光的金属球ComfyUI工作流
一条色彩斑斓的超现实小孔雀鱼ComfyUI工作流
一个精心制作的微型赛车场ComfyUI工作流
雪地里一只可爱的小老虎
一个外国人在吹奏萨克斯ComfyUI工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

利用CSS3代码编写45款按钮效果
一个包含老黄历、佛历、道历、星宿等数据的日历网站
如何利用css3+js做一个下雨效果
css3实现星球旋转
在线生成金属文字
利用css绘画棋盘布局(象棋)
用svg画出游泳池动画效果











