在小程序webview内嵌的h5页面中调用wx.chooseImage触发刷新页面?
发布于 5 年前 作者 yong54 12563 次浏览 来自 问答
在小程序webview内嵌的h5页面中调用wx.chooseImage拍照触发刷新页面,app.js以及当前页面的onshow里并没有逻辑代码,只有拍照有这个问题,相册没有。是什么原因啊

uploadImage() {
      let that = this;
      if (window.__wxjs_environment === "miniprogram") {
        wx.miniProgram.getEnv(function (res{
          if (res.miniprogram) {
            wx.chooseImage({
              count: that.count,
              successfunction (req{
                that.totalUpload = false
                that.syncUpload(req.localIds)
              },
              fail() {
                Toast.fail("选择图片失败!");
              },
            });
          }
        });
      }
    },
    syncUpload(localIds) {
      const localId = localIds.pop();
      const that = this
      wx.uploadImage({
        localId: localId, // 需要上传的图片的本地ID,由chooseImage接口获得
        isShowProgressTips0,
        successfunction (resp{
          that.handleUpload2(resp.serverId)
          if(localIds.length > 0){
            that.syncUpload(localIds);
            return
          }else{
            that.totalUpload = true
          }
        }
      });
    },
    handleUpload(data){
      Toast.loading({
        message'正在上传...',
        forbidClicktrue,
        loadingType'spinner',
        duration0
      })
      uploadWxFile({codeName:data}).then(response=>{
        this.fileList.push({
          id: response.fileMidId,
          url: response.fileUrl,
        })
        this.$emit("change"this.fileList)
        if(this.totalUpload){
          Toast.clear()
        }
      }).catch(()=>{
        if(this.totalUpload){
          Toast.clear()
        }
        this.$toast.fail('上传失败!')
      })
    },
回到顶部