Last active
October 20, 2020 06:48
-
-
Save 2234839/39df5befeb5dcb3fc2c2c34bd4ebb026 to your computer and use it in GitHub Desktop.
崮生的代码片段
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const copy = (str: string) => { | |
// 第一种 | |
navigator.clipboard.writeText(str); | |
}; | |
export const copy2 = (str: string) => { | |
// 第二种 | |
const input = document.createElement("textarea"); | |
input.style.opacity = "0"; | |
document.body.appendChild(input); | |
input.value = str; | |
input.select(); | |
const r = document.execCommand("copy"); | |
input.remove(); | |
return r; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment