当前位置:主页 > 查看内容

微信内h5页面打开小程序

发布时间:2021-07-30 00:00| 位朋友查看

简介:相关配置 微信js文件版本大于等于1.6.0 https://res.wx.qq.com/open/js/jweixin-1.6.0.js 微信授权配置 window.wx.config({ ...otherConfig, openTagList: ['wx-open-launch-weapp']}) 调用示例 const style = { position: 'absolute', top: 0, right: 0, bo……

相关配置

  1. 微信js文件版本大于等于1.6.0
    https://res.wx.qq.com/open/js/jweixin-1.6.0.js
  2. 微信授权配置

    window.wx.config({
     ...otherConfig,
     openTagList: ['wx-open-launch-weapp']
    })
  3. 调用示例

    const style = {
      position: 'absolute',
      top: 0,
      right: 0,
      bottom: 0,
      left: 0,
    };
    
    function OpenWeapp({ originId, pagePath }) {
      return (
     <wx-open-launch-weapp username={originId} path={pagePath} style={style}>
       <script type="text/wxtag-template">
         <div style={style} />
       </script>
     </wx-open-launch-weapp>
      );
    }
    
    // 使用方式
    <div style={{ position: 'relative' }}>
    点击跳转小程序
    <OpenWeapp originId="gh_xxxxxxxx" pagePath="pages/home/index?user=123&action=abc" />
    </div>
    

为什么给div添加position: relative呢?

由于wx-open-launch-weapp设置样式比较困难,故放弃设置样式,将wx-open-launch-weapp作为一个透明的占位元素,撑满父元素,也能达到预期的功能


本文转自网络,版权归原作者所有,原文链接:https://segmentfault.com/a/1190000040429064
本站部分内容转载于网络,版权归原作者所有,转载之目的在于传播更多优秀技术内容,如有侵权请联系QQ/微信:153890879删除,谢谢!

推荐图文


随机推荐