composition API 中实现一键复制
代码语言:javascript复制<input
type="text"
...
onfocus="this.select()"
ref="inputLink"
>
代码语言:javascript复制...
const inputLink = ref({} as unknown);
...
const copyLink = () => {
(inputLink.value as HTMLInputElement).select();
document.execCommand("copy");
alert("复制成功");
}
主要用到 DOM.select(); 和 document.execCommand("copy");