微信小程序 - cb回调(typeof cb == "function" && cb(obj);)
2023-09-11 14:14:36 时间
typeof cb == "function" && cb(obj)
但凡用了Promise,这种方式就可以抛弃了.
Page({
data: {},
onLoad() {
request('https://api.it120.cc/jy02149522/banner/list', {
type: 0
}, function(obj) {
console.log('请求到的数据:', obj)
})
}
})
// request请求封装
const request = (url, data, cb) => (
wx.request({
url,
data,
method: 'GET',
header: {
'content-type': 'application/x-www-form-urlencoded'
},
dataType: 'json',
responseType: 'text',
success(res) {
//判断cb是不是function,并且执行这行这个function
res.data.code == 0 ? typeof cb == "function" && cb(res.data) : typeof error === 'function' && error()
},
fail() {
typeof error === 'function' && error()
},
complete(res) {
// res.data.code != 0 ? typeof cb == "function" && cb(res.data) : typeof error === 'function' && error()
}
})
)
各位看官,自个理会.
相关文章
- 解决Gradle执行命令时报Could not determine the dependencies of task ':compileReleaseJava'.
- Linux下的Mysql安装 & 配置
- C# (初入江湖)-注释&命名规则
- 【微信小程序】-- 分包 - 独立分包 & 分包预下载(四十五)
- 【微信小程序】-- 全局配置 -- window - 下拉刷新 & 上拉触底(十六)
- 【微信小程序】-- WXML 模板语法 - 事件绑定 -- tap & input (十)
- 【微信小程序】-- 其它常用组件介绍 -- button & image(八)
- 【微信小程序】--WXML & WXSS & JS 逻辑交互介绍(四)
- 基于Linux进程共享内存&进程共享mutex实现的订票系统
- 微信小程序 - 带参数跳转页面参数字段文章内容太长或包含特殊字符(“?“,“&“ 或 “=“)导致被截取或失败
- Command: command & type
- 【创】C/C++无向图的创建-邻接表表示法& DFS & BFS
- 后台执行循环(done &)
- (数据科学学习手札13)K-medoids聚类算法原理简介&Python与R的实现
- 微信小程序如何使用解析  ; <; >; &; &apos; &ensp; &emsp;等字符?
- poj 1659 Frogs' Neighborhood 度序列可图化 贪心
- HDU 1242 -Rescue (双向BFS)&&( BFS+优先队列)
- Java Annotations: Explored & Explained--转载
- [原创] 树莓派个人实测 Q&A(最新修改使用windows连接远程桌面)
- 微信小程序中常见的typeof cb == “function” && cb(that.globalData.userInfo)