Created
October 25, 2020 13:53
-
-
Save ThaddeusJiang/22eb0281e386a1299a272dd54dc80068 to your computer and use it in GitHub Desktop.
setTimeout revert uncopied in vue 3 |
This file contains hidden or 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
<template> | |
<button @click="onClick">{{ copied ? "copied" : "copy" }}</button> | |
</template> | |
<script> | |
import { ref, watchEffect } from "vue"; | |
export default { | |
setup() { | |
const copied = ref(false); | |
const onClick = () => (copied.value = true); | |
watchEffect(() => { | |
if (copied.value) { | |
setTimeout(() => { | |
copied.value = false; | |
}, 2000); | |
} | |
}); | |
return { copied, onClick }; | |
}, | |
}; | |
</script> | |
<style scoped> | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment