Просмотр исходного кода

feat: allow passing directive definition directly to h() (#12590)

Kael 3 лет назад
Родитель
Сommit
d45bbeac27
2 измененных файлов с 4 добавлено и 2 удалено
  1. 2 2
      src/core/vdom/modules/directives.ts
  2. 2 0
      types/vnode.d.ts

+ 2 - 2
src/core/vdom/modules/directives.ts

@@ -94,7 +94,7 @@ function normalizeDirectives(
     // $flow-disable-line
     return res
   }
-  let i, dir
+  let i: number, dir: VNodeDirective
   for (i = 0; i < dirs.length; i++) {
     dir = dirs[i]
     if (!dir.modifiers) {
@@ -103,7 +103,7 @@ function normalizeDirectives(
     }
     res[getRawDirName(dir)] = dir
     if (vm._setupState && vm._setupState.__sfc) {
-      dir.def = resolveAsset(vm, '_setupState', 'v-' + dir.name)
+      dir.def = dir.def || resolveAsset(vm, '_setupState', 'v-' + dir.name)
     }
     dir.def = dir.def || resolveAsset(vm.$options, 'directives', dir.name, true)
   }

+ 2 - 0
types/vnode.d.ts

@@ -1,4 +1,5 @@
 import { Vue } from './vue'
+import { DirectiveFunction, DirectiveOptions } from './options'
 
 export type ScopedSlot = (props: any) => ScopedSlotReturnValue
 type ScopedSlotReturnValue =
@@ -86,4 +87,5 @@ export interface VNodeDirective {
   arg?: string
   oldArg?: string
   modifiers?: { [key: string]: boolean }
+  def?: DirectiveFunction | DirectiveOptions
 }