unplugin / unplugin-vue-components

📲 On-demand components auto importing for Vue

Home Page:https://www.npmjs.com/package/unplugin-vue-components

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

当组件名和自定义指令名重名时无法正常使用该指令(Vite+Vue3+ElementPlus)

zaeyee opened this issue · comments

问题描述

当components目录下有Auth.vue组件,同时又自定义了auth指令时,Auth组件能正常使用,但v-auth指令将不生效。
必须在directives选项为true或使用ElementPlusResolver时才能复现。

期望效果

Auth组件正常使用、v-auth指令也能正常使用

解决建议

在查看源代码后,发现可能的原因是:解析组件和解析指令方法用的是同一个map对象,导致先解析到Auth组件并缓存,再解析auth指令时直接使用了缓存。是否可以额外使用一个map对象缓存解析到的指令呢?或是其他更好的解决方式?

部分截图

图片

Please provide a minimum reproduction repo.

我也遇到了同样的问题,我看看能不能提供个最小成本复现吧

Please provide a minimum reproduction repo.

https://github.com/hooray/unplugin-vue-components-directives
可以看这个仓库,首先有一个 Auth 组件,然后当 directives: true 时,v-auth 无法正常被注册,当 directives: false 时,v-auth 正常注册,并且触发时在控制台有内容输出

Please provide a minimum reproduction repo.

https://github.com/hooray/unplugin-vue-components-directives
可以看这个仓库,首先有一个 Auth 组件,然后当 directives: true 时,v-auth 无法正常被注册,当 directives: false 时,v-auth 正常注册,并且触发时在控制台有内容输出

感谢提供,我最近比较忙,没注意到回复,你提供的代码没问题,感谢感谢!

commented

是否有必要添加一个directives的目录的配置项,来搜索里面自定义指令函数并引入,类似unplugin-auto-import。