Skip to content

Commit aa2b1f4

Browse files
committed
feat: directive resolution for <script setup>
1 parent 4b19339 commit aa2b1f4

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/core/vdom/modules/directives.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ function normalizeDirectives(
102102
dir.modifiers = emptyModifiers
103103
}
104104
res[getRawDirName(dir)] = dir
105-
dir.def = resolveAsset(vm.$options, 'directives', dir.name, true)
105+
if (vm._setupState && vm._setupState.__sfc) {
106+
dir.def = resolveAsset(vm, '_setupState', 'v-' + dir.name)
107+
}
108+
dir.def = dir.def || resolveAsset(vm.$options, 'directives', dir.name, true)
106109
}
107110
// $flow-disable-line
108111
return res

test/unit/features/v3/apiSetup.spec.ts

+14
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,18 @@ describe('api: setup context', () => {
233233
await nextTick()
234234
expect(vm.$el.outerHTML).toMatch(`<div>1</div>`)
235235
})
236+
237+
it('directive resolution', () => {
238+
const spy = vi.fn()
239+
new Vue({
240+
setup: () => ({
241+
__sfc: true,
242+
vDir: {
243+
inserted: spy
244+
}
245+
}),
246+
template: `<div v-dir />`
247+
}).$mount()
248+
expect(spy).toHaveBeenCalled()
249+
})
236250
})

0 commit comments

Comments
 (0)