Skip to content

Instantly share code, notes, and snippets.

@Inndy
Created October 19, 2023 10:09
Show Gist options
  • Save Inndy/87f197af9bd5c761b28d69a90af95ab0 to your computer and use it in GitHub Desktop.
Save Inndy/87f197af9bd5c761b28d69a90af95ab0 to your computer and use it in GitHub Desktop.
import { Tooltip } from 'bootstrap';
import { nextTick } from 'vue';
const attrName = 'data-bs-title';
const contextAttrName = '__v_bs_tooltip__';
export default {
install(app, options) {
app.directive('bs-tooltip', {
mounted(el, binding, vnode, prevVnode) {
el.setAttribute(attrName, `${binding.value}`);
el[contextAttrName] = new Tooltip(el);
},
componentUpdated(el, binding, vnode, prevVnode) {
nextTick(() => {
el.setAttribute(attrName, `${binding.value}`);
el[contextAttrName]._config.title = binding.value;
});
},
unmounted(el, binding, vnode, prevVnode) {
el[contextAttrName].dispose();
delete el[contextAttrName];
el.removeAttribute(attrName);
},
})
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment