文档

剪贴板

更新时间:

my.getClipboard

说明:mPaaS 10.1.32 及以上版本支持该接口。


此接口用于获取剪贴板数据。

入参

名称 类型 必填 描述
success Function 调用成功的回调函数
fail Function 调用失败的回调函数
complete Function 调用结束的回调函数(调用成功、失败都会执行)

success 返回值

名称 类型 描述
text String 剪贴板数据

代码示例

  1. // API-DEMO page/API/clipboard/clipboard.json
  2. {
  3. "defaultTitle": "Clipboard"
  4. }
  1. <!-- API-DEMO page/API/clipboard/clipboard.axml-->
  2. <view class="page">
  3. <view class="page-section">
  4. <view class="page-section-title">setClipboard</view>
  5. <view class="page-section-demo">
  6. <input onInput="handleInput" value="{{text}}" />
  7. <button class="clipboard-button" type="primary" size="mini" onTap="handleCopy">复制</button>
  8. </view>
  9. </view>
  10. <view class="page-section">
  11. <view class="page-section-title">getClipboard</view>
  12. <view class="page-section-demo">
  13. <input onInput="bindInput" value="{{copy}}" disabled />
  14. <button class="clipboard-button" type="default" size="mini" onTap="handlePaste">粘贴</button>
  15. </view>
  16. </view>
  17. </view>
  1. // API-DEMO page/API/clipboard/clipboard.js
  2. Page({
  3. data: {
  4. text: '3.1415926',
  5. copy: '',
  6. },
  7. handleInput(e) {
  8. this.setData({
  9. text: e.detail.value,
  10. });
  11. },
  12. handleCopy() {
  13. my.setClipboard({
  14. text: this.data.text,
  15. });
  16. },
  17. handlePaste() {
  18. my.getClipboard({
  19. success: ({ text }) => {
  20. this.setData({ copy: text });
  21. },
  22. });
  23. },
  24. });
  1. /* API-DEMO page/API/clipboard/clipboard.acss */
  2. .clipboard-button {
  3. margin-left: 5px;
  4. }

my.setClipboard

说明:mPaaS 10.1.32 及以上版本支持该接口。


此接口用于设置剪贴板数据。

入参

名称 类型 必填 描述
text String 剪贴板数据
success Function 调用成功的回调函数
fail Function 调用失败的回调函数
complete Function 调用结束的回调函数(调用成功、失败都会执行)

代码示例

  1. // API-DEMO page/API/clipboard/clipboard.json
  2. {
  3. "defaultTitle": "Clipboard"
  4. }
  1. <!-- API-DEMO page/API/clipboard/clipboard.axml-->
  2. <view class="page">
  3. <view class="page-section">
  4. <view class="page-section-title">setClipboard</view>
  5. <view class="page-section-demo">
  6. <input onInput="handleInput" value="{{text}}" />
  7. <button class="clipboard-button" type="primary" size="mini" onTap="handleCopy">复制</button>
  8. </view>
  9. </view>
  10. <view class="page-section">
  11. <view class="page-section-title">getClipboard</view>
  12. <view class="page-section-demo">
  13. <input onInput="bindInput" value="{{copy}}" disabled />
  14. <button class="clipboard-button" type="default" size="mini" onTap="handlePaste">粘贴</button>
  15. </view>
  16. </view>
  17. </view>
  1. // API-DEMO page/API/clipboard/clipboard.js
  2. Page({
  3. data: {
  4. text: '3.1415926',
  5. copy: '',
  6. },
  7. handleInput(e) {
  8. this.setData({
  9. text: e.detail.value,
  10. });
  11. },
  12. handleCopy() {
  13. my.setClipboard({
  14. text: this.data.text,
  15. });
  16. },
  17. handlePaste() {
  18. my.getClipboard({
  19. success: ({ text }) => {
  20. this.setData({ copy: text });
  21. },
  22. });
  23. },
  24. });
  1. /* API-DEMO page/API/clipboard/clipboard.acss */
  2. .clipboard-button {
  3. margin-left: 5px;
  4. }
  • 本页导读 (0)
文档反馈