Преглед изворни кода

feat: directive resolution for `<script setup>`

Evan You пре 3 година
родитељ
комит
aa2b1f4d93
2 измењених фајлова са 18 додато и 1 уклоњено
  1. 4 1
      src/core/vdom/modules/directives.ts
  2. 14 0
      test/unit/features/v3/apiSetup.spec.ts

+ 4 - 1
src/core/vdom/modules/directives.ts

@@ -102,7 +102,10 @@ function normalizeDirectives(
       dir.modifiers = emptyModifiers
     }
     res[getRawDirName(dir)] = dir
-    dir.def = resolveAsset(vm.$options, 'directives', dir.name, true)
+    if (vm._setupState && vm._setupState.__sfc) {
+      dir.def = resolveAsset(vm, '_setupState', 'v-' + dir.name)
+    }
+    dir.def = dir.def || resolveAsset(vm.$options, 'directives', dir.name, true)
   }
   // $flow-disable-line
   return res

+ 14 - 0
test/unit/features/v3/apiSetup.spec.ts

@@ -233,4 +233,18 @@ describe('api: setup context', () => {
     await nextTick()
     expect(vm.$el.outerHTML).toMatch(`<div>1</div>`)
   })
+
+  it('directive resolution', () => {
+    const spy = vi.fn()
+    new Vue({
+      setup: () => ({
+        __sfc: true,
+        vDir: {
+          inserted: spy
+        }
+      }),
+      template: `<div v-dir />`
+    }).$mount()
+    expect(spy).toHaveBeenCalled()
+  })
 })