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);
    });
});
相关推荐
鹿心肺语5 小时前
前端HTML转PDF的两种主流方案深度解析
前端·javascript
海石6 小时前
去到比北方更北的地方—2025年终总结
前端·ai编程·年终总结
一个懒人懒人6 小时前
Promise async/await与fetch的概念
前端·javascript·html
Mintopia6 小时前
Web 安全与反编译源码下的权限设计:构筑前后端一致的防护体系
前端·安全
输出输入6 小时前
前端核心技术
开发语言·前端
Mintopia6 小时前
Web 安全与反编译源码下的权限设计:构建前后端一体的信任防线
前端·安全·编译原理
林深现海6 小时前
Jetson Orin nano/nx刷机后无法打开chrome/firefox浏览器
前端·chrome·firefox
黄诂多7 小时前
APP原生与H5互调Bridge技术原理及基础使用
前端
前端市界7 小时前
用 React 手搓一个 3D 翻页书籍组件,呼吸海浪式翻页,交互体验带感!
前端·架构·github
文艺理科生7 小时前
Nginx 路径映射深度解析:从本地开发到生产交付的底层哲学
前端·后端·架构