Skip to content

Instantly share code, notes, and snippets.

@ThaddeusJiang
Created October 25, 2020 13:53
Show Gist options
  • Save ThaddeusJiang/22eb0281e386a1299a272dd54dc80068 to your computer and use it in GitHub Desktop.
Save ThaddeusJiang/22eb0281e386a1299a272dd54dc80068 to your computer and use it in GitHub Desktop.
setTimeout revert uncopied in vue 3 |
<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