Nhảy tới nội dung

my.getClipboard

getClipboard

my.getClipboard là API dùng để lấy nội dung từ clipboard của thiết bị.

Khả dụng: hỗ trợ từ version 1.79.1 trở lên.

Quét mã để trải nghiệm

Xem code mẫu trên Tini Studio

Demo

Trải nghiệm thử với trình giả lập bên dưới

API Params

Thuộc tínhKiểu dữ liệuMô tả
successFunctionCallback function khi lấy dữ liệu từ clipboard thành công.
failFunctionCallback function khi lấy dữ liệu từ clipboard bất thành.
completeFunctionCallback function khi việc lấy dữ liệu từ clipboard hoàn tất bất kể thành công hay thất bại.

Callback function payload

Thuộc tínhKiểu dữ liệuMô tả
textstringNội dung của clipboard.

Sample Code

index.js
Page({
data: {
text: undefined
},
textChange(e) {
this.setData({
text: e.detail.value
});
},
onSetClipboard() {
my.setClipboard({
text: this.data.text,
success: (res) => {
my.alert({ title: 'Success' });
},
fail: (e) => {
my.alert({ title: 'error', content: JSON.stringify(e) });
}
});
},
onGetClipboard() {
my.getClipboard({
success: (res) => {
my.alert({ title: 'Success', content: res.text });
},
fail: (e) => {
my.alert({ title: 'error', content: JSON.stringify(e) });
}
});
}
});
index.txml
<view>
<block-header title="Usage" description="Get/Set clipboard" />
<view class="block-content">
Input text
</view>
<input class="form-value" placeholder="" name="text" onInput="textChange"></input>
<view class="block-content">
<button class="button-full" onTap="onSetClipboard">Set Clipboard</button>
<button class="button-full" onTap="onGetClipboard">Get Clipboard</button>
</view>
</view>