Clipboard
The Clipboard API reads and writes the system clipboard.
Try it online
Quick copy
Import
ts
import woo from 'mini-sdk'
// 或
import { clipboard } from 'mini-sdk'API reference
setClipboard
Writes text to the clipboard.
ts
woo.setClipboard(options: { text: string }): Promise<void>ts
await woo.setClipboard({ text: '复制的内容' })
woo.showToast('已复制到剪贴板')getClipboard
Reads the clipboard.
ts
woo.getClipboard(): Promise<{ text: string }>ts
const { text } = await woo.getClipboard()
console.log('剪贴板内容:', text)End-to-end example
vue
<script setup>
import woo from 'mini-sdk'
async function copyShareLink(id) {
const link = `https://app.example.com/share/${id}`
await woo.setClipboard({ text: link })
woo.showToast({ title: '链接已复制', icon: 'success' })
}
async function pasteAndSearch() {
try {
const { text } = await woo.getClipboard()
if (text) await performSearch(text)
} catch {
woo.showToast({ title: '无法读取剪贴板', icon: 'none' })
}
}
</script>tsx
import woo from 'mini-sdk'
function ShareButton({ id }: { id: string }) {
async function copyShareLink() {
const link = `https://app.example.com/share/${id}`
await woo.setClipboard({ text: link })
woo.showToast({ title: '链接已复制', icon: 'success' })
}
async function pasteAndSearch() {
try {
const { text } = await woo.getClipboard()
if (text) await performSearch(text)
} catch {
woo.showToast({ title: '无法读取剪贴板', icon: 'none' })
}
}
return <button onClick={copyShareLink}>复制链接</button>
}API quick reference
| Method | Description | Signature |
|---|---|---|
setClipboardData | Set clipboard content | ({ data }) → Promise<void> |
getClipboardData | Get clipboard content | () → Promise<{ data }> |