Giter VIP home page Giter VIP logo

vue-axios's Issues

请问,如果不想在每个页面中去判断是否成功在去执行操作,可以如下这样吗?

getData(){
this.$axios.get("/h5/grammar/study/v3.0.0/list", {student_grunit_id: 1}, (data)=>{
HT.log("【"+this.$options.name+"】", data)
});
},


【http.js】
function checkCode (res, callback) {
// 如果code异常(这里已经包括网络错误,服务器错误,后端抛出的错误),可以弹出一个错误提示,告诉用户
if (res.status === -404) {
alert(res.msg)
}
if (res.data && (res.data.errcode != "200")) {
alert(res.data.errmsg) ### //只提示错误,不执行操作
}

if (res.data && (res.data.errcode == "200")) {
    callback(res.data) //成功并执行回调函数
}

}

提点意见

图片
我这里返回的状态是 ok 所以你这段错误检测写的还不健壮
if (res.data && (!res.data.success)) { alert(res.data.error_msg) }
错误信息的判断也没有多少,只有一个网络错误

封装问题

老铁,这最后错误抛出的封装为什么用then,不用catch啊

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.