This interface is used to get the clipboard data.
my.getClipboard
mPaaS 10.1.32 and later versions support this interface.
This interface is used to get the clipboard data.
Input parameter
Name | Type | Required | Description |
success | Function | No | Callback function for successful call |
fail | Function | No | Callback function for failed call |
complete | Function | No | Callback function for ended call (executed regardless of whether the call is successful or failed) |
success return value
Name | Type | Description |
text | String | Clipboard data |
Sample code
// API-DEMO page/API/clipboard/clipboard.json
{
"defaultTitle": "Clipboard"
}<!-- API-DEMO page/API/clipboard/clipboard.axml-->
<view class="page">
<view class="page-section">
<view class="page-section-title">setClipboard</view>
<view class="page-section-demo">
<input onInput="handleInput" value="{{text}}" />
<button class="clipboard-button" type="primary" size="mini" onTap="handleCopy">copy</button>
</view>
</view>
<view class="page-section">
<view class="page-section-title">getClipboard</view>
<view class="page-section-demo">
<input onInput="bindInput" value="{{copy}}" disabled />
<button class="clipboard-button" type="default" size="mini" onTap="handlePaste">paste</button>
</view>
</view>
</view>// API-DEMO page/API/clipboard/clipboard.js
Page({
data: {
text: '3.1415926',
copy: '',
},
handleInput(e) {
this.setData({
text: e.detail.value,
});
},
handleCopy() {
my.setClipboard({
text: this.data.text,
});
},
handlePaste() {
my.getClipboard({
success: ({ text }) => {
this.setData({ copy: text });
},
});
},
});/* API-DEMO page/API/clipboard/clipboard.acss */
.clipboard-button {
margin-left: 5px;
}my.setClipboard
mPaaS 10.1.32 and later versions support this interface.
This interface is used to set the clipboard data.
Input parameter
Name | Type | Required | Description |
text | String | Yes | Clipboard data |
success | Function | No | Callback function for successful call |
fail | Function | No | Callback function for failed call |
complete | Function | No | Callback function for ended call (executed regardless of whether the call is successful or failed) |
Sample code
// API-DEMO page/API/clipboard/clipboard.json
{
"defaultTitle": "Clipboard"
}<!-- API-DEMO page/API/clipboard/clipboard.axml-->
<view class="page">
<view class="page-section">
<view class="page-section-title">setClipboard</view>
<view class="page-section-demo">
<input onInput="handleInput" value="{{text}}" />
<button class="clipboard-button" type="primary" size="mini" onTap="handleCopy">copy</button>
</view>
</view>
<view class="page-section">
<view class="page-section-title">getClipboard</view>
<view class="page-section-demo">
<input onInput="bindInput" value="{{copy}}" disabled />
<button class="clipboard-button" type="default" size="mini" onTap="handlePaste">paste</button>
</view>
</view>
</view>// API-DEMO page/API/clipboard/clipboard.js
Page({
data: {
text: '3.1415926',
copy: '',
},
handleInput(e) {
this.setData({
text: e.detail.value,
});
},
handleCopy() {
my.setClipboard({
text: this.data.text,
});
},
handlePaste() {
my.getClipboard({
success: ({ text }) => {
this.setData({ copy: text });
},
});
},
});/* API-DEMO page/API/clipboard/clipboard.acss */
.clipboard-button {
margin-left: 5px;
}