老师7-15 通用错误异常处理(重要)这一小节

来源:7-15 通用错误异常处理(重要)

webFE

2019-04-30

修改appkey报错一样,但是不显示错误的背景图片,帮忙看看吧
http.js

//引入模块config.js
import {config} from '…/config.js’
class HTTP{
request (params){
wx.request({
url: config.api_base_url + params.url,
method:params.method,
data:params.data,
header:{
‘content-type’:‘application/json’,
‘appkey’:config.appkey
},
success:(res) => {
//code是数字得先转换成字符串
let code = res.statusCode.toString();
//statsWidth
//endsWidth
if ( code.startsWith(‘2’) ) {
params.success(res);
} else {
wx.wx.showToast({
title: ‘错误’,
icon: ‘none’,
duration: 2000

                })
            }
        },
        fail:(res) => {
            wx.wx.showToast({
                title: '错误',
                icon: 'none',
                duration: 2000
               
            })
        }
    })
}

}
//将http这个类输出去
export {HTTP}

classic.js

import {HTTP} from ‘…/…/util/http.js’

let http = new HTTP();
// pages/classic/classic.js
Page({

/**

  • 页面的初始数据
    */
    data: {
    test:1
    },

/**

  • 生命周期函数–监听页面加载
    */
    onLoad: function (options) {
    http.request({
    url:’/classic/latest’,
    success:(res) => {
    console.log(res.data);
    }
    })

    /* wx.request({
    url: ‘http://bl.7yue.pro/v1/classic/latest’,
    data: {},
    header: {
    appkey:‘7w6bioA6IQP6s2gy’
    },
    method: ‘GET’,
    dataType: ‘json’,
    responseType: ‘text’,
    success: (res)=>{
    console.log(this.data.test)
    },
    fail: ()=>{},
    complete: ()=>{}
    }); */
    },

/**

  • 生命周期函数–监听页面初次渲染完成
    */
    onReady: function () {

},

/**

  • 生命周期函数–监听页面显示
    */
    onShow: function () {

},

/**

  • 生命周期函数–监听页面隐藏
    */
    onHide: function () {

},

/**

  • 生命周期函数–监听页面卸载
    */
    onUnload: function () {

},

/**

  • 页面相关事件处理函数–监听用户下拉动作
    */
    onPullDownRefresh: function () {

},

/**

  • 页面上拉触底事件的处理函数
    */
    onReachBottom: function () {

},

/**

  • 用户点击右上角分享
    */
    onShareAppMessage: function () {

}
})

写回答

1回答

7七月

2019-04-30

什么意思,可否详细描述下,问题是什么?错误提示是什么?

0
0

纯正商业级微信小程序应用实战,全方位小程序特性讲解

真实数据的高质量小程序项目,学会直接工作

4782 学习 · 2125 问题

查看课程