diff --git a/src/core/vdom/modules/directives.ts b/src/core/vdom/modules/directives.ts index 0dc61e9279..7d475de1fc 100644 --- a/src/core/vdom/modules/directives.ts +++ b/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 diff --git a/test/unit/features/v3/apiSetup.spec.ts b/test/unit/features/v3/apiSetup.spec.ts index f3c152b48c..44044ed22b 100644 --- a/test/unit/features/v3/apiSetup.spec.ts +++ b/test/unit/features/v3/apiSetup.spec.ts @@ -233,4 +233,18 @@ describe('api: setup context', () => { await nextTick() expect(vm.$el.outerHTML).toMatch(`