vue 移动端今天写了一个根据后台传过来的http状态码,来实现跳转error页面

来源:互联网 发布:mac 游戏加速器 编辑:程序博客网 时间:2024/05/18 02:24

首先是现在main.js里面进行配置

Vue.prototype.$onError = function (error) {    var error_msg = '网络错误';    var toastFlag = true;    switch (error.errorCode) {        case 401:            error_msg = '请先登录';            break;        case 500:            error_msg = '服务器错误';            break;        case 504:            error_msg = '网络超时'            break;        case 20000:            toastFlag = false;            this.$router.push({path: 'invalidIdentity'});            break;    }    if(toastFlag){        this.$Toast({            message: error_msg,            position: 'bottom',            duration: 2000,            callback: () => {                this.$router.push({path: 'error'});            }        })    }}
然后在每个接口后面加上function(err)就可以了

下面举例一个借口

siteService.sales(this.time).then(res => {    vm.salesInfo = res.data;    vm.details = vm.salesInfo.details;    vm.saleSum = vm.salesInfo.saleSum;    vm.time = vm.salesInfo.time;}, err => {    this.$onError(err);});
这就实现了error页面的跳转了

阅读全文
0 0
原创粉丝点击