Last active
July 15, 2018 14:06
-
-
Save adi518/daf20b62bd7f79fa07e36d1ce01adb11 to your computer and use it in GitHub Desktop.
This file contains 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
// Compatible with Vue.js | |
function getElementByRef(ref, refs) { | |
refs = refs || this.$refs | |
const noRefs = !refs | |
if (noRefs) { | |
console.error(`[getElementByRef warn]: No refs found.`) | |
return | |
} | |
let element = refs[ref] | |
// Is from element? | |
if (element instanceof Element) { | |
return element | |
} | |
// Is from component? | |
if (refs[ref]) { | |
element = refs[ref].el | |
if (element instanceof Element) { | |
return element | |
} | |
} | |
// Ref doesn't exist | |
console.error(`[getElementByRef warn]: No such ref as "${ref}".`) | |
return null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment