swan.getClipboardData

解释:获取系统剪贴板内容
Web 态说明:由于 Web 态环境安全策略限制,该功能无法支持,会返回失败回调。

方法参数

Object object

object 参数说明

属性名类型必填默认值说明

success

Function

接口调用成功的回调函数

fail

Function

接口调用失败的回调函数

complete

Function

接口调用结束的回调函数(调用成功、失败都会执行)

success 返回参数说明

参数名类型说明

data

String

剪贴板的内容

示例

扫码体验

代码示例

百度智能小程序

请使用百度APP扫码

图片示例

swan.getClipboardData - 图2

代码示例 1

在开发者工具中打开

在开发者工具中打开

在 WEB IDE 中打开

  • SWAN
  • JS
  1. <view class="wrap">
  2. <view class="card-area">
  3. <view class="list-area border-bottom">
  4. <text class="list-item-key-4">原文本</text>
  5. <text class="list-item-value">{{originData}}</text>
  6. </view>
  7. <view class="list-area border-bottom">
  8. <text class="list-item-key-4">复制文本</text>
  9. <text class="list-item-value">{{clipboardData}}</text>
  10. </view>
  11. <button bind:tap="setClipboardData" type="primary" hover-stop-propagation="true">复制</button>
  12. <button bind:tap="getClipboardData" type="primary" hover-stop-propagation="true">粘贴</button>
  13. </view>
  14. </view>

代码示例 2

在开发者工具中打开

在开发者工具中打开

在 WEB IDE 中打开

  • SWAN
  • JS
  1. <view class="wrap">
  2. <view class="card-area">
  3. <view class="top-description border-bottom">
  4. 小程序中只有text节点可以进行复制操作,用户在其他非小程序进行了复制操作,也可放到这里
  5. </view>
  6. <view class="content">{{content}}</view>
  7. <button bind:tap="getClipboardData" type="primary" hover-stop-propagation="true">点击粘贴</button>
  8. </view>
  9. </view>

错误码

Android

错误码说明

1001

执行失败