Taro+Vue3,点击按钮把另一个页面分享出去

useShareAppMessage

监听用户点击页面内转发按钮(Button 组件 openType='share')或右上角菜单"转发"按钮的行为,并自定义转发内容。等同于 onShareAppMessage 页面生命周期钩子。

使用时,必须为页面配置 enableShareAppMessage: true。(修改配置文件后请重新编译项目)

复制代码
button属性open-type="share"

useShareAppMessage((res) => {
  console.log(res)
  if (res.from === 'button') {
    // 来自页面内转发按钮
    console.log(res.target)
  }
  return {
    title: '请收下我的名片',
    path: `pages/other/fa/index?id=${user.id}`
  }
})

被分享的页面

复制代码
import { useDidShow, getCurrentInstance } from '@tarojs/taro'
const instance = getCurrentInstance();

useDidShow(() => {
    // 通过页面实例获取ID
    id.value = instance.router?.params?.id;
    console.log('获取到的ID:', id.value);
    // 进一步处理获取到的ID
    const params: any = {
        id: id.value
    };
    net.selectMember(params).then((res: any) => {
        //res 为返回数据
        console.log(res.list[0]);
        users.name = res.list[0].name
        users.position = res.list[0].cardPosition
        users.phone = res.list[0].cardPhone
        users.email = res.list[0].cardEmail
        users.slogan = res.list[0].cardSlogan
        users.wechat = res.list[0].cardWechat
    }, (err: any) => {
        //err为错误信息,请按提示修改
        console.log(err);
    });
});
相关推荐
于慨1 天前
Lambda 表达式、方法引用(Method Reference)语法
java·前端·servlet
石小石Orz1 天前
油猴脚本实现生产环境加载本地qiankun子应用
前端·架构
从前慢丶1 天前
前端交互规范(Web 端)
前端
@yanyu6661 天前
07-引入element布局及spring boot完善后端
javascript·vue.js·spring boot
CHU7290351 天前
便捷约玩,沉浸推理:线上剧本杀APP功能版块设计详解
前端·小程序
GISer_Jing1 天前
Page-agent MCP结构
前端·人工智能
王霸天1 天前
💥别再抄网上的Scale缩放代码了!50行源码教你写一个永不翻车的大屏适配
前端·vue.js·数据可视化
小领航1 天前
用 Three.js + Vue 3 打造炫酷的 3D 行政地图可视化组件
前端·github
@大迁世界1 天前
2026年React大洗牌:React Hooks 将迎来重大升级
前端·javascript·react.js·前端框架·ecmascript
PieroPc1 天前
一个功能强大的 Web 端标签设计和打印工具,支持服务器端直接打印到局域网打印机。Fastapi + html
前端·html·fastapi