第一种:可以在任何地方调用函数
function fn(){
console.log('fn')
}
第二种:表达式 调用必须在函数调用之后
var fn1 = function(){
console.log('fn1')
}
fn1()
函数
function 函数名(形参){}
函数名(实参)
参数可以是任意类型的值 数值 数组 字符串 布尔类型 对象 函数
回调函数:函数作为参数
function show(success){
var a = 10
b=15
success(a+b)
}
show(function(v){
console.log('回调函数',v)
})
show((v)=>{
console.log('箭头函数',v)
})
小程序的回调
首先在utils下面创建request.js文件
在request.js文件内写
function request(opents){
// API-->界面-->-->交互
wx.showLoading({
title:'数据加载中',
})
//API--->网络--->发起请求
wx:request({
url:opents.method,
data:{},
header:{
'content-type': 'application/json'
},
success(res){
'opents-type':'application/json'
},
//API--->界面--->交互
complete:()=>{
wx:hideLoading()
}
})
}
//抛出
module.exports={
request
}
上拉加载
loading加载写在请求前
wx.showLoading({
title:'数据加载中',
})
接口调用结束的回调函数
complete:()=>{
wx.hideLoding()
}
页面相关事件处理函数-监听用户下拉动作
onPullDownRefresh() {
// API-->界面-->下拉刷新
wx.stopPullDownRefresh()
},