Skip to content

Instantly share code, notes, and snippets.

@clw8
Last active January 19, 2019 11:30
Show Gist options
  • Save clw8/28c7cd3e8f1fd8cbbd82d9bdf1d7c3d9 to your computer and use it in GitHub Desktop.
Save clw8/28c7cd3e8f1fd8cbbd82d9bdf1d7c3d9 to your computer and use it in GitHub Desktop.
#vue #javascript
// under script
// simple dumb component called Tooltip has been created that takes props text and className
import Tooltip from '~/components/Tooltip.vue'
import Vue from 'vue'
// under methods....
insertCopyTooltip: function(row, index){
// dynamically insert tooltip!
// if tooltip already inserted, delete it from Vue and from the DOM
if( !!this.tooltipInstance ){
console.log(this.tooltipInstance);
this.tooltipInstance.$destroy();
this.tooltipInstance.$el.parentNode.removeChild(this.tooltipInstance.$el);
}
// create the vue component ( instantiate the component and add it to the DOM)
let span = document.createElement("span");
let container = this.$refs['tooltipContainer'].appendChild(span);
//Vue extend to create component class (creating a "subclass constructor of Vue")
let toolTipClass = Vue.extend(Tooltip);
// auth the component, passing it props
let instance = new toolTipClass({ propsData: { text: "Copied!", className: "tooltip-fade" }});
//mount the component in the DOM
instance.$mount(container);
this.tooltipInstance = instance;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment