在小程序js里面,在回掉函数里面写this,例如这样:
success: function(res) {
console.log(this)
}
会输出 NULL
也就是说找不到 this
解决办法
success: (res) => {
console.log(this)
}
或者这样写
let _this = this
......
success: function(res) {
console.log(this)
}
这是因为 this
的作用域问题