微信小程序携带参数跳转H5页面

跳转到webView页面

 tabberBack() {
    
    
        let taskId = wx.getStorageSync('taskId')
        var targetUrl = `https://apicgu.chinaucv.com/evaluation/?id=${
      
      taskId}`;
        wx.setStorageSync('urlWeb', targetUrl)
        // 跳转h5页面需要包装在小程序内,不能直接跳转
        wx.navigateTo({
    
    
            url:`../webPage/webPage`,
            success: function (res) {
    
    
                // 通过eventChannel向被打开页面传送数据
                res.eventChannel.emit('acceptDataFromOpenerPage', {
    
    
                    data: this.data.message
                })
            }
        })

web-view 创建一个页面

<view class="page-body">
  <web-view src="{
     
     {targetUrl}}"></web-view>
</view>
Page({
    
    
  data: {
    
    
   targetUrl: '' // 打开的h5页面的地址
  },
  onLoad: function(option){
    
    
    let url = wx.getStorageSync('urlWeb')
    // console.log('传过来什么地址', option.targetUrl)
    this.setData({
    
    
      targetUrl: url
    })
    const eventChannel = this.getOpenerEventChannel()
    // 监听acceptDataFromOpenerPage事件,获取上一页面通过eventChannel传送到当前页面的数据
    eventChannel.on('acceptDataFromOpenerPage', function(data) {
    
    
      console.log('上个页面传来了', data)
    })
  }
})

H5页面设置

async getList() {
    
    
      var id = window.location.href.split("=")[1]; //从小程序webview链接上获取id
      console.log(id, "传递的值");
      const {
    
     data: res } = await details({
    
     taskId: id });
      // const { data: res } = await details({ taskId: 63 });
      
      console.log(res);
      this.msg = res.content;
      res.content.imageDetailList.forEach((item) => {
    
    
        this.imgs.push(item.value);
      });
    },

猜你喜欢

转载自blog.csdn.net/weixin_46210850/article/details/121610064