Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
zaeyee opened this issue Apr 21, 2022 · 5 comments · Fixed by #440
Labels
bug Something isn't working

Comments

@zaeyee
Copy link

zaeyee commented Apr 21, 2022

问题描述

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

期望效果

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

解决建议

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

部分截图

图片

@sxzz sxzz added bug Something isn't working needs reproduction labels May 10, 2022
@sxzz
Copy link
Member

sxzz commented May 10, 2022

Please provide a minimum reproduction repo.

@hooray
Copy link

hooray commented May 16, 2022

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

@hooray
Copy link

hooray commented May 16, 2022

Please provide a minimum reproduction repo.

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

@zaeyee
Copy link
Author

zaeyee commented May 16, 2022

Please provide a minimum reproduction repo.

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

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

@Soya-xy
Copy link

Soya-xy commented May 27, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants