引用模块,继承模块,封装方法,调用封装方法
事件
1、事件回调success函数、和fail函数:无论api返回200还是400报错,都是调用success函数,只有访问api无返回,如网址错误,无网络等才会调用fail函数;
2、this、that,this作用域的问题在es6中可以用箭头函数解决
data:{
number:25
},
onLoad: function (options) {
console.log(this.data.number);//显示25
wx.request({
url:'',
success:function(){
console.log(this.data.number);//报错,this应变为that
},
success:()=>{
console.log(this.data.number);//显示25
}
});
}
小程序JS支持startWith、endWith函数
startsWith():返回[布尔值] 表示参数字符串是否在源字符串的头部。
endsWith():返回[布尔值] 表示参数字符串是否在源字符串的尾部
调试错误
错误报错的行数,从原文件看有时并不是该行数出错,因为这里给出的报错行数是在控制台source中的文件(不带sm)