Skip to content

Clipboard — 剪贴板

读取和写入系统剪贴板。

API 参考

woo.setClipboard(options)

写入剪贴板。
ts
await woo.setClipboard({ text: 'https://example.com/share?id=123' })
await woo.showToast({ title: '已复制链接', icon: 'success' })

Options

参数类型必填说明
textstring要写入的文本

woo.getClipboard()

读取剪贴板内容。
ts
const { text } = await woo.getClipboard()
console.log('剪贴板内容:', text)

// 粘贴到输入框
const clipResult = await woo.getClipboard()
inputRef.value = clipResult.text

Result

字段类型说明
textstring剪贴板文本内容

常见用法

分享链接按钮

ts
async function copyShareLink(id: string) {
  const url = `https://example.com/share?id=${id}`
  await woo.setClipboard({ text: url })
  await woo.showToast({ title: '链接已复制', icon: 'success', duration: 1500 })
}

粘贴填充输入框

ts
async function pasteFromClipboard() {
  const { text } = await woo.getClipboard()
  if (text) {
    formData.value.input = text
    await woo.showToast('已粘贴')
  }
}

兼容性

getClipboard 在 iOS 14+ 首次调用时会弹出系统权限弹窗,建议在用户主动点击"粘贴"按钮时调用,而非自动触发。

基于 OpenSumi IDE 构建