RT,微信小程序的分享按钮是灰色的,是不是代码问题,悬赏50NL求解
要在前端代码加
具体去小程序文档搜 onShareAppMessage 那个
这里 https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/miniapp/component/onShareAppMessage.html
@“苏无名”#p98301 具体加在哪呢?
@“loll”#p98307
其实就是写在JS部分,添加一个方法,要分享哪个页面,就在哪个页面的JS部分加上
如果你是uniapp,而且用了setup语法糖的话
`
<script setup>
import { onShareAppMessage } from '@dcloudio/uni-app';
onShareAppMessage(res) {
if (res.from === 'button') {// 来自页面内分享按钮
console.log(res.target)
}
return {
title: '自定义分享标题',
path: '/pages/test/test?id=123'
}
}
</setup>
`
如果是2.0的传统写法
`
export default {
onShareAppMessage(res) {
if (res.from === 'button') {// 来自页面内分享按钮
console.log(res.target)
}
return {
title: '自定义分享标题',
path: '/pages/test/test?id=123'
}
}
}
`
@“苏无名”#p98310 直接加在页面代码末端可以吗
可以,和onLoad, onShow同级即可,别加在这些事件里边了里边了
@“苏无名”#p98313 有没有实例啊啥的纯小白
@“loll”#p98314 等我吃完饭这一个给你
@“苏无名”#p98316 看下私信
@“loll”#p98314 算了,你看这里
以最简单的UNIAPP的pages/index/index举例,
**用组合式API就这么写**
[upl-image-preview url=https://s.rmimg.com/2024-09-30/1727697820-464089-image.png]
点击效果
[upl-image-preview url=https://s.rmimg.com/2024-09-30/1727699482-313956-1.png]
**用传统的选项式API就这么写**
[upl-image-preview url=https://s.rmimg.com/2024-09-30/1727698367-90363-image.png]
点击效果
[upl-image-preview url=https://s.rmimg.com/2024-09-30/1727699516-200112-2.png]
**如果你用的是原生的小程序写法**
[upl-image-preview url=https://s.rmimg.com/2024-09-30/1727699103-53121-image.png]
点击效果
[upl-image-preview url=https://s.rmimg.com/2024-09-30/1727699530-499805-3.png]
就酱紫:ac01: 一定要关掉 es6转es5
@“苏无名”#p98359 为什么添加完代码分享按钮偶尔有偶尔没有呢?
@“loll”#p99175 看有没有报错,另外,清理缓存
@“苏无名”#p99260 没有报错啊,也清理缓存了