aliang888
aliang888
  • 发布:2020-07-29 22:23
  • 更新:2021-05-25 11:40
  • 阅读:11265

【分享】uniapp环境开H5端打开微信小程序,解决苹果端首次进入页面显示异常

分类:uni-app
<wx-open-launch-weapp path="pages/card/visit_card.html?id=19" id="launch-wxapp" username="gh_abc199886dfa">  
        <script type="text/wxtag-template">  
            <style>  
                .btn-open-weapp{  
                    background: linear-gradient(to right, #ffd52e 0%, #ffef93 50%, #ffd52e 100%);  
                    border: 0;  
                    color: #424242;  
                    text-shadow: 0px 1px 1px #fff;  
                    border-radius: 50px;  
                    text-align: center;  
                    width: 120px;  
                    height: 35px;  
                    line-height: 35px;  
                    outline:none;  
                }  
            </style>  
            <button class="btn-open-weapp">进店逛逛</button >  
        <script>  
</wx-open-launch-weapp>`  

原来直接这样子用,发现有问题,安卓端正常,但苹果端首次进入H5页面显示不了按钮,只有刷新才能显示,于是折腾一翻,因为H5端支持v-html,测试了下一切正常

下面这种方式,微信开发者工具也能看到按钮哦

<!-- #ifdef H5 -->  
    <view v-html="wxOpenTags"></view>  
<!-- #endif --> 
//#ifdef H5  
    setTimeout(()=>{  
        this.wxOpenTags=`<wx-open-launch-weapp path="pages/card/visit_card.html?id=19" id="launch-wxapp" username="gh_abc199886dfa">  
            <template>  
                <style>  
                .btn-open-weapp{  
                    background: linear-gradient(to right, #ffd52e 0%, #ffef93 50%, #ffd52e 100%);  
                    border: 0;  
                    color: #424242;  
                    text-shadow: 0px 1px 1px #fff;  
                    border-radius: 50px;  
                    text-align: center;  
                    width: 120px;  
                    height: 35px;  
                    line-height: 35px;  
                    outline:none;  
                }  
                </style>  
                <button class="btn-open-weapp">进店逛逛</button >  
            </template>  
        </wx-open-launch-weapp>`;  
    },1000);  
//#endif

wx-open-launch-app也用v-html的方式

0 关注 分享

要回复文章请先登录注册

wanghexu

wanghexu

我的报错了,报错信息是Unknown custom element: <wx-open-launch-weapp> - did you register the component correctly? For recursive components, make sure to provide the "name" option.
说组件没注册,我使用最新版的微信开发工具,和真机浏览器,都试过了。版本号和系统都是超过标准的
2020-08-11 18:19
wanghexu

wanghexu

js呢?在哪里引入的????
2020-08-11 18:12
aliang888

aliang888 (作者)

回复 supersu :
样式可以生效啊,你的代码帖出来看看
2020-08-03 22:19
[已删除]

[已删除]

承接前端H5、小程序、APP、PC端网站等外包,主要技术栈为vue、uni-app,有意请加微信:13192733603(我是前端,找有渠道接外包的服务端合伙人)
2020-08-01 09:43
supersu

supersu

请问你配置的样式能生效吗,我写的样式只有背景色成功了
2020-08-01 09:15