Last active
June 18, 2021 00:57
-
-
Save titusdecali/1e4dc360ac187f10ce8199048d4d5e75 to your computer and use it in GitHub Desktop.
Global Vue Utility Function Example
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
// import store from '../store' <-- To access your Vuex store | |
import Vue from 'vue' // <-- used for vue-toastification | |
class Utils { | |
// Copy a string to user's clipboard | |
copyToClipboard(text) { | |
let copyText = document.createElement('input') | |
document.body.appendChild(copyText) | |
copyText.value = text | |
copyText.select() | |
document.execCommand('copy') | |
document.body.removeChild(copyText) | |
// Show toast on copy success | |
// (using the vue-toastification package here) | |
Vue.$toast.success('Copied address to clipboard: ' + text, { | |
position: 'top-right', | |
timeout: 3000 | |
}) | |
} | |
} | |
export default new Utils() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment