小程序错误收集

1.this.setData is not a function

在微信小程序中我们一般通过以下方式来修改data中的数据

1
2
3
4
5
6
7
8
this.setData({
imageUrl:imageUrlStr
})
```
但是当我们通过`wx.request`请求网络数据成功后绑定数据时使用此方法就会报错

this.setData is not a function

1
2
3
4
5
6
7
8
这是因为`this`作用域只想问题,`success`函数实际是一个闭包,无法直接通过`this`来`setData`
解决办法:
在请求`(wx.request)`外面添加:

var that=this;

1
2
3
`success`中使用

that.setData({
imageUrl:imageUrlStr
})

1
2
3
4
5
6
7
8
这样就可以正常使用了。
### 2.`request:fail url not in domain list`
开发版本不会存在这个问题,不是调试环境就会报错。
解决方法:

去微信小程序后台-设置-开发设置-服务器域名
配置request合法域名
这样就可以正常使用了
```

3.css中无法读取本地资源

.wxss中使用background-image属性不能加载本地资源,在电脑模拟器上显示正常,在真机上不显示

解决方法:

  • 1.使用网络资源background-image: url(http://xxx.com/icon-arrowdown.png);

  • 2.无法解决问题(在电脑模拟器上显示正常,在真机上不显示)(在.wxml中使用加载本地资源,<view class="with_arrow" style='background-image: url(/resource/meList/icon_arrow_r.png);'>

  • 3.使用base64转码(图片路径会很长很长)
  • 4.使用image标签代替背景图片