小程序的thirdScriptError ..... is not a function 报错的解决方法

简介: 小程序的thirdScriptError ..... is not a function 报错的解决方法

在这里先说下我做的案例,顺便大家可以看看

项目样式图

前端代码

//前端代码
<!--团队介绍  -->
    <view class="m-team" wx:if="{{tabs[2].selected}}">
        <view bindtap="onTapAddMember" class="m-addBtn">
            <view>+ 添加成员</view>
        </view>
        <view class="m-memberItem m-clear" wx:for="{{memberList}}" wx:key="uniqueMember">
            <view bindtap="onTapDelMember" class="m-delMemeber" data-memberid="{{item.id}}">
                <image src="../../resource/icon-del.png"></image>
            </view>
            <view catchtap="onTapChangeMemberAvatar" class="m-memberAvatar" data-avatar="{{item.id}}">
                <image mode="aspectFill" src="{{item.avatarSrc}}"></image>
            </view>
            <view class="m-memberInfo" style="width:{{memberInfoWidth}}px">
                <input bindinput="onTapInputTeam" data-id="{{item.id}}" data-name="name" placeholder="姓名" type="text" value="{{item.name}}"></input>
                <input bindinput="onTapInputTeam" data-id="{{item.id}}" data-name="position" placeholder="公司职位" type="text" value="{{item.position}}"></input>
            </view>
            <view catchtap="onTapUpMember" class="m-upTeamArrow" data-id="{{item.id}}" wx:if="{{index==0?fale:true}}">
                <image src="../../resource/upArrow.png"></image>
            </view>
            <view catchtap="onTapDownMember" class="m-downTeamArrow" data-id="{{item.id}}" wx:if="{{index==memberList.length-1?fale:true}}">
                <image src="../../resource/upArrow.png"></image>
            </view>
        </view>

上传图片的方法

//上传图片 
// param img 图片;
function fileupload(mdl = '', callback) {
  var datas = [];
  wx.chooseImage({
    count: 1, // 默认9
    sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
    sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
    success: function (res) {
      var tempFilePaths = res.tempFilePaths;
      // wx.showLoading({
      //   title: '图片上传中..',
      // })
      wx.uploadFile({
        url: 'https://www.weiuid.com/index.php/api/upload/upload', //仅为示例,非真实的接口地址
        filePath: tempFilePaths[0],
        name: 'file',
        formData: {
          'mdl': mdl
        },
        success: function (res) {
          wx.hideLoading();
          // wx.showToast({
          //   title: '上传成功',
          // });
          var data = JSON.parse(res.data);//你大爷的强制返回字符串;强制转json
          callback(data.data);
          // console.log(callback(data.data))
        },
        fail: function (res) {
          wx.showToast({
            title: '图片上传中',
          });
        }
      });
    }
  });
}

添加图片的代码,为了避免数据库压力过大,将数据存储到缓存里边,这边调用了一个图片上传的方法

// 添加成员
    onTapAddMember: function() {
      var e = this.data.memberList, a = "new-" + e.length;
      wxb.that = this;
      wxb.fileupload('', function (data) {
        // 判断上传的路径是否为空
        if (data.img != '') {
          var i = {
            id: a,
            avatarSrc: data.img_url,
            name:'',
            position:'',
            isCreate: !0,
          }; 
        //这里将数据存放到了提前声明的数组里边
          e.push(i);
          console.log(e)
        //将数据存到缓存中
          wx.setStorageSync('memberList', e)
        //将缓存的数据保存起来,使用缓存来循环,可以加快页面加载速度
          wxb.that.setData({
            memberList: e
          });
        } else {
          wx.showToast({
            title: '上传失败',
          })
        }
      }); 
    },

使用了上边代码之后就可以直接将成员信息循环出来,现在就还存在一个问题就是,如果上传了多个成员信息,姓名和职位怎么一一对应的填写上


添加姓名和职位的方法,姓名和职位都有俩个自定义的属性,使用循环将名字和职位添加进去。


所有的数据都在s里边保存这,所以把最终的数据是s,把s在一次存放到缓存即可

    // 添加成员姓名和职位
    onTapInputTeam: function(e) {
        for (var a = e.currentTarget.dataset.id, t = e.currentTarget.dataset.name, o = e.detail.value, s = this.data.memberList, n = 0; n < s.length; n++) a == s[n].id && (s[n].isUpdate = !0, 
        "name" == t ? s[n].name = o : "position" == t ? s[n].position = o : console.log("error"));
        // 将新添加的数据全部放到缓存里边
        wx.setStorageSync('memberList',s);
    },

当没有发布就退出之后,再次进来就没有之前编写的东西,所以我们在onload里边获取缓存的数据


这里要着重说一下这里的坑,onload是一进小程序就会直接加载的,所有当你把内存清理之后,就会报出一个错,说在*****不是一个方法。


解决这个问题很是简单,我们俩分析分析原因,我们在一开始就直接获取了memberList这个缓存,但是注意的是这里并获取不到数据,所以会直接把一个未知的变量给赋值到this.data.memberList,所以在点击上传的时候就会出现,push不进去东西,因为只有数组才可以push进去东西。


所以就需要这样的处理一下,做一个判断,判断当从缓存拿不到数据的时候,给这个data里边的数据重新附一个【】空数组的值,在设置值,这样就不会报错了。问题完美解决

var memberLists = wx.getStorageSync('memberList');
        if (!memberLists){
          memberLists = [];
        }
        this.setData({
          memberList: memberLists
        });
相关文章
|
API C++
【Azure 环境】VS Code登录China Azure(Function)报错 An error occurred while signing in: invalid_request - AADSTS65002
An error occurred while signing in: invalid_request - AADSTS65002: Consent between first party application 'c27c220f-ce2f-4904-927d-333864217eeb' and first party resource '797f4846-ba00-4fd7-ba43-dac1f8f63013' must be configured via preauthorization - applications owned and operated by Microsoft mus
667 13
|
缓存 开发工具 C++
VS Code调试Function报错|无法加载Diagnostics.Abstractions怎么办?
在调试 Azure Function 时,可能出现 “Could not load file or assembly &#39;Microsoft.Extensions.Diagnostics.Abstractions, Version=8.0.0.0&#39;” 错误,导致主机启动失败。本文详细解析该依赖加载错误的成因,并提供基于不同安装方式(NPM 或 MSI)的解决方案,涵盖重装 Core Tools、清理缓存、检查 .NET SDK 版本等操作步骤,同时提供日志排查与 Docker 容器化替代方案,帮助开发者快速恢复本地调试流程。
538 0
|
JSON 小程序 JavaScript
uni-app开发微信小程序的报错[渲染层错误]排查及解决
uni-app开发微信小程序的报错[渲染层错误]排查及解决
5088 7
|
网络协议 API 网络安全
【Azure Function App】发现部分请求Function App遇见 403.72 报错(请求Body>100KB)
在调用Azure Function的HTTP Trigger时,发送POST请求偶尔出现403错误,且响应为空、Header信息少。经排查发现,当请求Body大于100KB时会触发403.72错误,原因是启用了“Client Certificate mode”为“Optional Interactive User”。解决方法是将该模式设置为“Ignore”。由于TLS重新协商机制限制,大请求体无法正常处理,导致此问题。
510 1
|
Java Windows
【Azure Function】部署Java Function失败:报错deploy [ERROR] Status code 401和警告 'China North 3' may not be a valid region
1:deploy [ERROR] Status code 401, (empty body). 2: China North 3 may not be a valid region,please refer to https://aka.ms/maven_function_configuration#supported-regions for values. 3:  <azure.functions.maven.plugin.version>1.36.0</azure.functions.maven.plugin.version>
685 11
|
Linux Python
【Azure Function】Python Function部署到Azure后报错No module named '_cffi_backend'
ERROR: Error: No module named '_cffi_backend', Cannot find module. Please check the requirements.txt file for the missing module.
589 2
解决微软云Azure Function运行报错-Value cannot be null. (Parameter ‘provider‘)
解决微软云Azure Function运行报错-Value cannot be null. (Parameter ‘provider‘)
550 4
|
缓存
【Azure Function】Function App代码中使用Managed Identity认证获取Blob数据时遇见400报错
【Azure Function】Function App代码中使用Managed Identity认证获取Blob数据时遇见400报错
405 0
【Azure Function】Function App代码中使用Managed Identity认证获取Blob数据时遇见400报错
|
JSON Java Serverless
函数计算操作报错合集之报错Function time out after该怎么办
Serverless 应用引擎(SAE)是阿里云提供的Serverless PaaS平台,支持Spring Cloud、Dubbo、HSF等主流微服务框架,简化应用的部署、运维和弹性伸缩。在使用SAE过程中,可能会遇到各种操作报错。以下是一些常见的报错情况及其可能的原因和解决方法。
717 2

热门文章

最新文章