Skip to content

Instantly share code, notes, and snippets.

@titusdecali
Last active June 18, 2021 00:57
Show Gist options
  • Save titusdecali/1e4dc360ac187f10ce8199048d4d5e75 to your computer and use it in GitHub Desktop.
Save titusdecali/1e4dc360ac187f10ce8199048d4d5e75 to your computer and use it in GitHub Desktop.
Global Vue Utility Function Example
// 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