首先用到useRef, 将ref绑定到input上面
<Input value={url} ref={urlInputRef} />
然后使用如下代码
const copy = () => {
const elem = urlInputRef.current;
if (elem == null) return;
elem.select();
document.execCommand("copy");
message.success("拷贝成功");
};
Comments
Post a Comment