feat: directive resolution for <script setup>

This commit is contained in:
Evan You 2022-06-15 21:21:59 +08:00
parent 4b193390fb
commit aa2b1f4d93
2 changed files with 18 additions and 1 deletions

View File

@ -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

View File

@ -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()
})
})