剪贴板

扫码体验:img.jpg

my.getClipboard

获取剪贴板数据。扫码体验:

入参

名称类型必填描述
successFunction调用成功的回调函数
failFunction调用失败的回调函数
completeFunction调用结束的回调函数(调用成功、失败都会执行)

success 返回值

名称类型描述
textString剪贴板数据

代码示例

  1. Page({
  2. data: {
  3. text: '3.1415926',
  4. copy: '',
  5. },
  6. handlePaste() {
  7. my.getClipboard({
  8. success: ({ text }) => {
  9. this.setData({ copy: text });
  10. },
  11. });
  12. },
  13. });

my.setClipboard

设置剪贴板数据。

入参

名称类型必填描述
textString剪贴板数据
successFunction调用成功的回调函数
failFunction调用失败的回调函数
completeFunction调用结束的回调函数(调用成功、失败都会执行)

代码示例

  1. Page({
  2. data: {
  3. text: '3.1415926',
  4. copy: '',
  5. },
  6. handleCopy() {
  7. my.setClipboard({
  8. text: this.data.text,
  9. });
  10. },
  11. });

原文: https://docs.alipay.com/mini/api/clipboard