代码实例

image class="avatar" src="{{postData.avatar}}"/image

上述代码中,即使变量的图片路径是对的, 在控制台也会报一个错误:

VM421:2 Failed to load image http://livec.dev/storage/ : the server responded with a status of 404 (HTTP/1.1 404 Not Found) From server 127.0.0.1

网上查找,原因在于初始化的时候,变量还没渲染进去,导致src为错误的值,我也不知道为什么会这样.

简单处理方法
利用wx:if判断,当变量存在时才渲染,可以解决报错问题.    可能以后的版本会修复这个bug.

解决方法

image wx:if="{{postData.avatar}}" class="avatar" src="{{postData.avatar}}"/image

以上.

TAG标签: 微信小程序500报错

http://www.xiaochengxub.com/read-104268.html