Skip to content

Instantly share code, notes, and snippets.

@Mosharush
Last active June 22, 2023 19:30
Show Gist options
  • Save Mosharush/95c379ff2cf8f8b977b0c12196ea40bd to your computer and use it in GitHub Desktop.
Save Mosharush/95c379ff2cf8f8b977b0c12196ea40bd to your computer and use it in GitHub Desktop.
Function to get closest vue instance from DOM element
export function getClosestVueInstance (elm) {
if (!elm) return;
const parentNode = elm.parentNode;
const vueInstance = parentNode?.__vue__;
return vueInstance ?? getClosestVueInstance(parentNode);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment