Nhảy tới nội dung

my.setClipboard

setClipboard

my.setClipboard là API dùng để đưa dữ liệu vào 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ệuBắt buộcMô tả
textstringDữ liệu cần đưa vào clipboard
successFunctionCallback function khi đưa dữ liệu vào clipboard thành công.
failFunctionCallback function khi việc đưa dữ liệu vào clipboard bất thành.
completeFunctionCallback function khi việc dữ liệu vào clipboard hoàn tất bất kể thành công hay thất bại .

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>