Created
October 19, 2023 10:09
-
-
Save Inndy/87f197af9bd5c761b28d69a90af95ab0 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
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