Skip to content
On this page

useCopy

控制 剪切板内容

Demo

当前剪切板内容:

Usage

html
<template>
  <div   >
    <div>当前剪切板内容: {{ text }}</div>
    <button @click="change">更改剪切板内容</button>
  </div>
</template>

<script lang="ts" setup>
import { useCopy } from '@morehook/core'

const text = useCopy()

function change() {
  text.value = Math.random()
}
</script>

Type Declarations

typescript
/**
 * onSuccess: 成功回调
 * onError: 失败回调
 */
interface Options {
  onSuccess?: (str: Str) => void
  onError?: (str: Str) => void
}
type Str = undefined | string | number | boolean | object | (() => void)
/**
 * 控制 剪切板内容
 * 警告: 必须在网页聚焦时才能正常使用
 * @param str 剪切板初始化时的内容
 * @param options 如上 Options
 */
export declare function useCopy(str?: Str, options?: Options): Ref<Str>

Source

SourceDemoDocs