微信h5跳转至小程序

在开发微信公众号时,有两个菜单需跳转至小程序。
在这里插入图片描述

参考官方开发文档
在这里插入图片描述

由于菜单项是通过循环遍历出的,直接使用 wx-open-launch-weapp包裹住菜单项,发现在浏览器调试时,并不显示

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .nav a {
      display: block;
      text-align: center;
      border: 1px solid rgb(126, 115, 115);
      width: 100px;
      height: 100px;
      margin: 10px;
    }

    .nav a i {
      display: block;
      margin: 0 auto;
      width: 65px;
      height: 65px;
    }

    .nav a i img {
      display: block;
      width: 100%
    }

    .nav a strong {
      display: block;
      font-size: 14px;
      color: #333;
      font-weight: 200;
    }
   
  </style>
</head>

<body>
  <div class="nav">
    <a href="javascript:void(0);">
      <wx-open-launch-weapp style="width: 100%; height: 100%;" path="pages/webview/webview" username="gh_test1account">
        <script type="text/wxtag-template">
          <style>
            img {
              display: block;
              width: 100%;
            }
            strong {
              display: block;
              font-size: 12px;
              color: #333;
              font-weight: 200;
            }
          </style>
          <div class="toWrap">
            <i>
              <img src="https://img1.baidu.com/it/u=1955340679,2837494472&fm=26&fmt=auto">
            </i>
            <strong>来院导航</strong>
          </div>
        </script>
      </wx-open-launch-weapp>
    </a>
  </div>


</body>

</html>

在这里插入图片描述
因此,采用plan B,在原菜单项上加一个div放置weapp组件,并定位在父元素上方,此时菜单可显示,且点击也可跳转。
在这里插入图片描述

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .nav a {
      display: block;
      text-align: center;
      border: 1px solid rgb(126, 115, 115);
      width: 100px;
      height: 100px;
      margin: 10px;
    }

    .nav a i {
      display: block;
      margin: 0 auto;
      width: 65px;
      height: 65px;
    }

    .nav a i img {
      display: block;
      width: 100%
    }

    .nav a strong {
      display: block;
      font-size: 14px;
      color: #333;
      font-weight: 200;
    }
    .originA {
      position: relative;
    }

    .weappContainer {
      position: absolute;
      top: 0;
      left: 0;
      bottom: 0;
      right: 0;
      opacity: 0;
    }
  </style>
</head>

<body>
  <div class="nav">
    <a href="javascript:void(0);" class="originA">
      <i><img src="https://img1.baidu.com/it/u=1955340679,2837494472&fm=26&fmt=auto"></i>
      <strong>来院导航</strong>
      <div class="weappContainer">
        <wx-open-launch-weapp style="width: 100%; height: 100%;" path="pages/webview/webview"
          username="gh_test1account">
          <script type="text/wxtag-template">
            <style>
              .toWrap{
                display: flex;flex-direction: column;align-items: center;
                width: 100%;
                height: 100%;
                opacity: 0;
              }
              img {
                display: block;
                width: 100%;
              }
              strong {
                display: block;
                font-size: 12px;
                color: #333;
                font-weight: 200;
              }
            </style>
            <div class="toWrap">
              <i>
                <img src="https://img1.baidu.com/it/u=1955340679,2837494472&fm=26&fmt=auto">
              </i>
              <strong>来院导航</strong>
            </div>
          </script>
        </wx-open-launch-weapp>
      </div>
    </a>
  </div>


</body>

</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值