# Clipboard

## 例子

```
copy: function () {
    const {
      data
    } = this.data;
    wx.setClipboardData({
      data: `data`,
      success(res) {
        wx.showToast({
          title: '成功',
          icon: 'success',
          duration: 2000
        })
      }
    })
  },
```

命令解释：复制当前内容“data”内的数据，并显示复制成功字样。

涉及：

```
wx.setClipboardData
```

设置系统剪贴板的内容。调用成功后，会弹出 toast 提示"内容已复制"，持续 1.5s

### 参数 <a href="#can-shu" id="can-shu"></a>

#### Object object <a href="#object-object" id="object-object"></a>

| 属性       | 类型       | 默认值 | 必填 | 说明                       |
| -------- | -------- | --- | -- | ------------------------ |
| data     | string   |     | 是  | 剪贴板的内容                   |
| success  | function |     | 否  | 接口调用成功的回调函数              |
| fail     | function |     | 否  | 接口调用失败的回调函数              |
| complete | function |     | 否  | 接口调用结束的回调函数（调用成功、失败都会执行） |

```
wx.showToast
```

显示消息提示框

### 参数 <a href="#can-shu" id="can-shu"></a>

#### Object object <a href="#object-object" id="object-object"></a>

| 属性       | 类型       | 默认值       | 必填 | 说明                           | 最低版本                                                                                   |
| -------- | -------- | --------- | -- | ---------------------------- | -------------------------------------------------------------------------------------- |
| title    | string   |           | 是  | 提示的内容                        |                                                                                        |
| icon     | string   | 'success' | 否  | 图标                           |                                                                                        |
| image    | string   |           | 否  | 自定义图标的本地路径，image 的优先级高于 icon | [1.1.0](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) |
| duration | number   | 1500      | 否  | 提示的延迟时间                      |                                                                                        |
| mask     | boolean  | false     | 否  | 是否显示透明蒙层，防止触摸穿透              |                                                                                        |
| success  | function |           | 否  | 接口调用成功的回调函数                  |                                                                                        |
| fail     | function |           | 否  | 接口调用失败的回调函数                  |                                                                                        |
| complete | function |           | 否  | 接口调用结束的回调函数（调用成功、失败都会执行）     |                                                                                        |

**object.icon 的合法值**

| 值       | 说明                                                                                                                     | 最低版本 |
| ------- | ---------------------------------------------------------------------------------------------------------------------- | ---- |
| success | 显示成功图标，此时 title 文本最多显示 7 个汉字长度                                                                                         |      |
| loading | 显示加载图标，此时 title 文本最多显示 7 个汉字长度                                                                                         |      |
| none    | 不显示图标，此时 title 文本最多可显示两行，[1.9.0](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)及以上版本支持 |      |

```
wx.getClipboardData
```

获取系统剪贴板的内容

### 参数 <a href="#can-shu" id="can-shu"></a>

#### Object object <a href="#object-object" id="object-object"></a>

| 属性       | 类型       | 默认值 | 必填 | 说明                       |
| -------- | -------- | --- | -- | ------------------------ |
| success  | function |     | 否  | 接口调用成功的回调函数              |
| fail     | function |     | 否  | 接口调用失败的回调函数              |
| complete | function |     | 否  | 接口调用结束的回调函数（调用成功、失败都会执行） |

**object.success 回调函数**

**参数**

**Object object**

| 属性   | 类型     | 说明     |
| ---- | ------ | ------ |
| data | string | 剪贴板的内容 |

### 示例代码 <a href="#shi-li-dai-ma" id="shi-li-dai-ma"></a>

```
wx.getClipboardData({
  success (res){
    console.log(res.data)
  }
})
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.luckydesigner.space/wechat/pei-zhi/clipboard.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
