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

来源:未知 浏览 91次 时间 2021-06-10 04:10

1  微信小程序中调用豆瓣API接口时提示错误 GET 400 的解决方法如下

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

 

<span style="font-size:18px;">loadMovie:function(){  

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

    wx.request({  

      url: '', //仅为示例并非真实的接口地址  

      header: {  

        'content-type': 'application/json' // 默认值  

      },  

      success: function (res) {  

        console.log(res.data)  

      }  

    })  

  }</span>  

以上程序请求豆瓣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  微信小程序网站有排名没流量多加了一个  .name  
就比如:subject.genres下面就没有了如果加上一个subject.genres.name就会出出现上述错误

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

[html] view plain copy

 

<span style="font-size:18px;"><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></span>  

以上代码中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 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
代码如下
  

[html] view plain copy

 

<span style="font-size:18px;">loadMovie: function () {  

    var page = this;  

    wx.request({  

      url: '', //仅为示例并非真实的接口地址  

      header: {  

        'content-type': 'json' // 默认值  

      },  

      success: function (res) {  

  

  

        var subjects = res.data.subjects;  

        subjectUtil.processSubjects(subjects);  

        page.setData({ movies: subjects, hidden: true });  

      }  

标签: lt程序gtview