- 依赖
element-ui/elementUI-plus
- 自定义指令:
v-abbreviation
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| import ElementUI from "element-ui" export default { install(Vue) { let mt = null; Vue.directive('abbreviation', { inserted(element, binding) { const Popover1 = Vue.extend(ElementUI.Popover)
if (!mt) { const vmtest = new Popover1() mt = vmtest mt.trigger = "hover" mt.placement = 'bottom' } element.addEventListener('mouseover', function () { console.log('listen hover', element); if (element && element.scrollWidth > element.offsetWidth) { mt.reference = element mt.referenceElm = element mt.content = element.innerText mt.$mount() document.body.appendChild(mt.$el) } })
} }) } }
|
现已发布到npm: npm i Vabbreviation
安装