| 34 |
UniApp 添加微信小程序的分享功能 |
<p>1、page.json中在要添加分享的页面的style下面增加两句话</p>
<pre class=""><code class="language-json hljs">"enableShareAppMessage": true,
"enableShareTimeline": true</code></pre>
<p> </p>
<p>2、在对应页面的<script>里添加</p>
<pre class=""><code class="hljs language-xml">// 在 <script setup> 中直接定义分享函数
const onShareAppMessage = (res) => {
if (res.from === 'button') {
console.log(res.target)
}
return {
title: 'title',
path: '/pages/index/index',
}
}
// 如果需要分享到朋友圈
const onShareTimeline = () => {
return {
title: 'title',
query: `q=${searchKeyword.value}`
}
}
// 在onLoad中启用分享菜单
onLoad(() => {
// 显示转发按钮
uni.showShareMenu({
withShareTicket: true,
// 如果需要分享到朋友圈,添加以下配置
// #ifdef MP-WEIXIN
menus: ['shareAppMessage', 'shareTimeline']
// #endif
})
})</code></pre> |
1 |
22 |
1 |
1/24/26, 2:04 AM |
1/24/26, 9:55 AM |
View Edit Delete |