Bläddra i källkod

feat(分享): 开发微信小程序分享功能

Burt 2 år sedan
förälder
incheckning
f8f1139dcf
2 ändrade filer med 10 tillägg och 2 borttagningar
  1. 1 1
      README.md
  2. 9 1
      src/pages/index/index.vue

+ 1 - 1
README.md

@@ -34,7 +34,7 @@
 - [ ] 页面悬浮球
 - [ ] 导航栏返回or去首页
 - [ ] 自定义导航栏顶部机型适配
-- [ ] 微信小程序分享(好友+朋友圈)
+- [x] 微信小程序分享(好友+朋友圈)
 - [ ] 多tab列表功能
 - [ ] 抽奖转盘
 

+ 9 - 1
src/pages/index/index.vue

@@ -25,7 +25,7 @@ import { ref } from 'vue'
 import { useCountStore, useUserStore } from '@/store'
 import { http } from '@/utils/http'
 import { UserItem } from '@/typings'
-import { onShareAppMessage } from '@dcloudio/uni-app'
+import { onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'
 
 const countStore = useCountStore()
 const title = ref('Hello')
@@ -48,6 +48,7 @@ const handleRequest = () => {
   })
   console.log(res)
 }
+/** 激活“分享给好友” */
 onShareAppMessage((options: Page.ShareAppMessageOption): Page.CustomShareContent => {
   console.log('options:', options)
   return {
@@ -57,6 +58,13 @@ onShareAppMessage((options: Page.ShareAppMessageOption): Page.CustomShareContent
       'https://cip-shopping-page-0eysug01066a9e-1302818703.tcloudbaseapp.com/pretty-girl.png',
   }
 })
+/** 激活“分享到朋友圈”, 注意:需要先激活“分享给好友” */
+onShareTimeline((): Page.ShareTimelineContent => {
+  return {
+    title: '自定义分享标题',
+    query: 'a=1&b=2',
+  }
+})
 </script>
 
 <style>