tooltip-destroy
by Ea Bangalore
HTML
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div id="app" v-tooltip>
I'm the app
</div>
CSS
#app {
height: 80px;
width: 80px;
background-color: grey;
}
Babel + JSX
Vue.directive('tooltip', {
inserted(el) {
let component;
el.addEventListener('mouseenter', () => {
let Tooltip = Vue.extend({ template: `<div>I'm a tooltip</div>` });
component = new Tooltip().$mount();
document.getElementById('app').appendChild(component.$el);
});
el.addEventListener('mouseleave', () => {
document.getElementById('app').removeChild(component.$el);
component.$destroy();
});
}
})
new Vue({
el: '#app',
})