微信小程序开发 错误修改方法笔记

来源:互联网 发布:淘宝推广文案怎么写 编辑:程序博客网 时间:2024/06/02 02:24
1  微信小程序中调用豆瓣API接口时提示错误 GET http://api.douban.com/v2/movie/in_theaters 400 的解决方法如下
loadMovie:function(){    var page=this;    wx.request({      url: 'http://api.douban.com/v2/movie/in_theaters', //仅为示例,并非真实的接口地址      header: {        'content-type': 'application/json' // 默认值      },      success: function (res) {        console.log(res.data)      }    })  }
以上程序请求豆瓣API的时候出错不能够正常得到网站的数据,后来发现,官方给的那个默认值需要改一下,也就是
      header: {
        'content-type': 'application/json' // 默认值
      },
以上程序中的'application/json'
需要改成'json'

之后在运行就不会出错了。


2  微信小程序提示错误:Cannot read property 'name' of undefined;at pages/movie/movie page processSubject function


这种错误就是在程序某个位置过多查询了,多加了一个  .name  
就比如:subject.genres下面就没有了如果加上一个subject.genres.name就会出出现上述错误


3  微信小程序,循环提取数据bug,不能够循环提取已有的数组中的数据。

<block wx:for="movies"wx:key="*this">    <view class="movie">      <view class="pic">        <image src="item.images.medium" mode="aspectFit"/>      </view>      <view class="movie-info">        <view class="base-info">          <text>{{item.text}}</text>        </view>      </view>    </view>    <view calss="hr"></view>  </block>
以上代码中movie 无法正常提取其中的 text项
修改方法:将上述<block wx:for="movies"wx:key="*this">中的wx:for="movies"改成wx:for="{{movies}}"之后就能正常输出数据了。
        <image src="item.images.medium" mode="aspectFit"/>数代码改成<image src="{{item.images.medium}}" mode="aspectFit"/>
其中item代表当前这个数据即movies[i]因此通过两个大括号提取出来其中的数据就可以运行输出了。

4  微信小程序的背景无法充满屏幕。
在升级后的客户端默认height值改变了,需要在.wxss文件的最前端加上以下程序
page{
  height: 100%;
}


5  当引用其它JS文件时,在全局utils.js里配置完成后在调用窗口声明 var subjectUtil=require("../../utils/subjectUtil.js");
提示错误:Uncaught Error: module "pages/utils/subjectUtil.js" is not defined
解决方法是需要在 utils.js里写如下程序
module.exports={
  processSubject(你外部用的函数名): processSubject(内部声明的函数名),
  processSubjects: processSubjects
}




6  提示错误:appservice:16 GET http://api.douban.com/v2/movie/in_theaters net::ERR_NETWORK_CHANGED
检查以下自己电脑的网络,或者重启开发者程序。


7  当引用其它JS文件时会提示错误:
WAService.js:3 thirdScriptError


this.setData is not a function;at pages/recommend/recommend loadMovie function;at api request success callback function


TypeError: this.setData is not a function
代码如下
  

loadMovie: function () {    var page = this;    wx.request({      url: 'http://api.douban.com/v2/movie/top250', //仅为示例,并非真实的接口地址      header: {        'content-type': 'json' // 默认值      },      success: function (res) {        var subjects = res.data.subjects;        subjectUtil.processSubjects(subjects);        page.setData({ movies: subjects, hidden: true });      }    })  }

当把subjectUtil.processSubjects(subjects);
换成page.processSubjects(subjects);的时候并且在当前js文件里面定义函数就不会出错。但是没有解决调用其它文件里封装的函数。




8  提示错误:VM131:2 Failed to load image 
          http://239319157.debug.open.weixin.qq.com/pages/detail/detail : the server responded with a status of 404 (HTTP/1.1 404 Not Found) 


          From server 127.0.0.1
   官方说法是1.5.2引入的bug。换成之前版本就不会报错,但是图片却没有显示出来,这就很尴尬了。




9  bug:按键点击效果不能够正常显示
   bug:问题7

原创粉丝点击