首页 > 编程语言 >uni-app:微信小程序:分享给微信好友和分享到朋友圈(hbuilderx 3.7.3)

uni-app:微信小程序:分享给微信好友和分享到朋友圈(hbuilderx 3.7.3)

时间:2023-02-24 16:46:03浏览次数:48  
标签:微信 share 朋友圈 https 分享 com

一,代码:

<template>
    <view>
        <view style="margin-left: 20rpx;margin-top: 20rpx; width:710rpx;height:710rpx;background: gray;">
        <image class="banner" mode="aspectFit" 
        src="https://img.lhdtest.com/ware/slider/1908.jpg" />
        </view>
        <button class="shareBtn" type="default" data-name="shareBtn" open-type="share"> 
                        分享
        </button>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                
            }
        },
        onl oad(){
            //设置Menus菜单,使 发送给朋友/分享到朋友圈 两个按钮可以使用
            wx.showShareMenu({
                withShareTicket:true,
                menus:["shareAppMessage","shareTimeline"]
            })
        },
        //发送给微信好友
        onShareAppMessage(res) {
            console.log("分享:from:"+res.from);
            return {
               title: '中学古诗词背诵', //分享的名称
               path: '/pages/share/share',   //页面的路径
            }
        },
       //分享到朋友圈
       onShareTimeline(res) {
            return {
               title: '今天背诵了唐代诗人李白的《夜宿山寺》',
               type: 0,
               path: '/pages/share/share',
               imageUrl: "https://img.lhdtest.com/ware/slider/1908.jpg",
            }
        },

        methods: {
        }
    }
</script>

<style>
    .banner {
        width:100%;
        height:100%;
    }
</style>

说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest

         对应的源码可以访问这里获取: https://github.com/liuhongdi/
         或: https://gitee.com/liuhongdi

说明:作者:刘宏缔 邮箱: [email protected]

二,测试效果:

 

 

 

 

三,查看hbuilderx的版本: 

标签:微信,share,朋友圈,https,分享,com
From: https://www.cnblogs.com/architectforest/p/17152044.html

相关文章