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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值