After the applet webView page is forwarded, the page is blank

On the webView page of the applet, after clicking the button in the upper right corner to share, the link page to enter the share is blank

After re-entering the page, the page is blank. After using the computer to open, the error message is as follows

 

 1. Check whether the page address has been decoded after the page is forwarded

After the webview page is forwarded, the applet will transcode the url parameter. At this time, if the page address is not re-decoded, the page redrawing fails, resulting in a blank page

// index.js
// 获取应用实例
const app = getApp()
var util = require('../utils/util.js');
Page({
  data: {
    url:''
  },
  onLoad(options){    
    if(options.weburl){
      const weburl = decodeURIComponent(options.weburl)
      this.setData({
        url: weburl
      })
    }
  },   

  /**
  * 用户点击右上角分享
  */
  onShareAppMessage: function () {
    
  }
})

 2. Check that the sharing link of the page is not processed when the current page is shared

You need to use the onShareAppMessage method provided by the applet to reassemble the objects required for sharing, including the title of the share (title), the address of the page to share (path), and the image to share (imageUrl). After assembly, reassign.

/**
  * 用户点击右上角分享
  */
  onShareAppMessage: function (res) {
    console.log("分享", res)
    let shareObj = {
      tittle: res.title, //默认是小程序名称
      path: `/pages/product/index?weburl=${encodeURIComponent(res.webViewUrl)}`, //页面分享
      success: function(ress){
        // 转发成功之后的回调
        if(ress.errMsg == 'shareAppMessage:ok'){
          console.log("chenggon")
        }
      },
      fail: function(error){
        console.log("分享错误", error)
        // 转发失败之后的回调
     if(res.errMsg == 'shareAppMessage:fail cancel'){
      // 用户取消转发
     }else if(res.errMsg == 'shareAppMessage:fail'){
      // 转发失败,其中 detail message 为详细失败信息
     }
      },
      complete: function(){
        // 转发结束之后的回调(转发成不成功都会执行)
        
      }
    }
    return shareObj;
  }

3. Check the parameter settings of the backend of the applet. For example, whether the domain name setting of the applet business includes requests such as http, you need to set such requests to https in the background settings; the domain name of the applet interface, etc. need to be checked.

The link to the development documentation for mini programs on the WeChat platform is ready, and you can fly away directly~ wx.updateShareMenu(Object object) | WeChat Open Documentation WeChat Developer Platform Documentation https://developers.weixin.qq.com/miniprogram/dev/ api/share/wx.updateShareMenu.html

Guess you like

Origin blog.csdn.net/codingLeader/article/details/128184893