小程序跳转其他小程序

hgzhang 2020-06-16

两个小程序要绑定在一个微信公众平台!!!

//A小程序
<!--index.wxml-->
<view class="container">
//方法1
  <!-- <navigator target="miniProgram" open-type="navigate" app-id="{{BappId}}" path="{{path}}" extra-data="{{datas}}" version="develop" bindsuccess="toMiniProgramSuccess">
    </navigator> -->
//方法2
    <text class="user-motto" bindtap="isbindViewTap">{{motto}}</text>
    </view>
</view>

//获取应用实例
const app = getApp()

Page({
//方法1
  data: {
    BappId:‘1212‘,
  path:‘pages/index/index?id=123‘ ,
  datas: {name:‘安琪111‘},
    motto: ‘点击跳转‘,
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse(‘button.open-type.getUserInfo‘)
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: ‘../logs/logs‘
    })
  },
  toMiniProgramSuccess(res){
    //从其他小程序返回的时候触发
    wx.showToast({
      title: ‘通过超链接跳转其他小程序成功返回了‘
    })
},
//方法2
  isbindViewTap:function(){
    wx.showModal({
      title: ‘提示‘,
      content: ‘将跳转至B小程序‘,
      confirmColor: "#1aad19",//设置确认按钮为绿色
      showCancel: false,//不显示取消按钮
      success: function (sm) {
          wx.navigateToMiniProgram({
               appId: "121",//需要跳转的小程序的appId
               path: ‘pages/index/index‘,//跳转页面的路径如path/index/index
               extraData: {//传递的参数
                  Number: ‘121212‘,
               },
               envVersion: "trial",//线上版固定为release,开发为develop,体验版为trial
               success(res) {
                 // 打开成功
                 console.log("跳转成功");
               }
           });
          }
       })
  },
  
})
//app.json
{
  "pages":[
    "pages/index/index",
    "pages/logs/logs"
  ],"navigateToMiniProgramAppIdList": [
    "wxff106b10a98a63f3"
  ]
}

//B小程序接收
//app.js
//获取应用实例
App({
  onLaunch: function(options) {
    this.globalData.number=options.referrerInfo.extraData.Number
    console.log(this.globalData.number)
    // 展示本地存储能力
    var logs = wx.getStorageSync(‘logs‘) || []
    logs.unshift(Date.now())
    wx.setStorageSync(‘logs‘, logs)
  globalData: {
    number: ‘‘
  }
})
//index.js页面获取
const app = getApp()
Page({
   onLoad(){
        consloe.log(app.globalData.number)
    }
})

相关推荐

微信小程序研究 / 0评论 2019-10-31