swan.openShare

解释: 调起分享面板。Web 态说明:Web 态小程序运行在微信、QQ、QQ空间、微博、百度 Hi 内时,调用 openShare 会弹出引导浮层引导用户通过平台的分享能力进行分享;在非上述环境时会弹出分享面板提示用户复制链接并分享。

方法参数

Object object

object参数说明

函数返回值

Boolean result

返回值说明

反馈分享结果,成功或失败。

fail 返回值参数说明

Web 态

示例

扫码体验

请使用百度APP扫码

图片示例

代码示例1 - API调起分享面板 :

在开发者工具中预览效果 -

  1. <view class="wrap"> <button type="primary" bindtap="openShare">openShare</button></view>

-

  1. Page({ openShare() { swan.openShare({ title: '智能小程序示例', content: '世界很复杂,百度更懂你', path: '/pages/openShare/openShare?key=value', imageUrl: 'https://smartprogram.baidu.com/docs/img/logo_new.png', success: res => { swan.showToast({ title: '分享成功' }); console.log('openShare success', res); }, fail: err => { console.log('openShare fail', err); } }); }});

代码示例2 - 组件调起分享面板 :

在开发者工具中预览效果 -

  1. <view class="wrap"> <button type="primary" open-type="share">openShare</button></view>

Bug & Tip

-

  1. let path = '/a/b?key=' + encodeURIComponent('中文');

-