Skip to content

Instantly share code, notes, and snippets.

@andrejsharapov
Last active August 17, 2022 06:24
Show Gist options
  • Save andrejsharapov/242bbd365de99cc14b79be66582b18b3 to your computer and use it in GitHub Desktop.
Save andrejsharapov/242bbd365de99cc14b79be66582b18b3 to your computer and use it in GitHub Desktop.
Copy to clipboard
<script>
export default {
methods: {
async toClipboard() {
const textarea = document.querySelector('.code_area textarea');
try {
textarea.select();
document.execCommand('copy');
this.$notify({
type: 'success',
title: 'Успешно',
message: 'Скопировано в буфер обмена',
});
} catch (e) {
this.$notify({
type: 'error',
title: 'Ошибка',
message: 'Не удалось скопировать данные',
});
} finally {
textarea.blur();
}
},
},
};
</script>
<script>
export default {
methods: {
async toClipboard() {
try {
await navigator.clipboard.writeText(this.editor);
this.$notify({
title: 'Успешно',
message: 'Скопировано в буфер обмена',
type: 'success',
});
} catch (e) {
this.$notify({
title: 'Ошибка',
message: 'Не удалось скопировать данные',
type: 'error',
});
}
},
},
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment