如何根据wx.request中返回值结束代码?
发布于 5 年前 作者 czhang 1934 次浏览 来自 官方Issues

if (type ==“体验版”)

{

var url = app.globalData.url + ‘/coupon/heavy’;

var ii = utils.heavy(url,function(obj){

console.log(obj.data.code);

if(obj.data.code==200)

{

    wx.showToast({

    title: ‘已经购买体验订单,不能重复购买’,

    icon: ‘none’,

    mask: true,

    duration: 2000,

    });

return false;  //这里不生效 想要这下面不在执行

}

})

}

console.log(type );

5 回复

为啥要var 一个 ii,下图写错了一个地方 那个/coupon/heavy 后的这个‘去掉

return 就行了啊

utils.heavy()  方法返回一个值,根据这个值来判断接下来是否要执行

if (type ==“体验版”)

{

var url = app.globalData.url + ‘/coupon/heavy’;

var ii = utils.heavy(url,function(obj){

console.log(obj.data.code);

if(obj.data.code==200)

{

wx.showToast({

title: ‘已经购买体验订单,不能重复购买’,

icon: ‘none’,

mask: true,

duration: 2000,

});

return 2222;

}else{

return 1111;

}

})

console.log(ii);

}

// return false

var info = wx.getStorageSync(“memberInfo”);

console.log(‘info’,info);

const heavy = (url,cb) => {

var info = wx.getStorageSync(“memberInfo”);

wx.request({

url: url,

data: {

info: info[‘id’],

},

success: function (t) {

console.log( t);

var mag = t.data.code;

if (mag == 200) {

typeof cb == “function” && cb(t)

} else {

typeof error === ‘function’ && error()

}

}

})

}

多简单一问题

回到顶部