directives.ts 410 B

1234567891011121314151617181920
  1. /**
  2. * 注册全局的自定义指令
  3. */
  4. type typeKey = {
  5. [key: string]: any;
  6. }
  7. const allDirectives: typeKey = {
  8. title: {
  9. inserted (el: any) {
  10. const { clientWidth, scrollWidth, title } = el
  11. if (!title && scrollWidth > clientWidth) el.title = el.innerText
  12. }
  13. }
  14. }
  15. export default (Vue: any) => {
  16. Object.keys(allDirectives).forEach((n: any) => Vue.directive(n, allDirectives[n]))
  17. }