V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
fuxinya
V2EX  ›  Vue.js

[Vue3] 能否给匹配的所有元素自动加上自定义指令

  •  
  •   fuxinya · Sep 2, 2022 · 1960 views
    This topic created in 1335 days ago, the information mentioned may be changed or developed.

    比如我定义了一个auth指令,现想把所有的button元素自动加上v-auth指令,能否实现这个功能?

    5 replies    2022-09-05 09:40:26 +08:00
    Kaciras
        1
    Kaciras  
       Sep 2, 2022
    写个打包器插件
    wu67
        2
    wu67  
       Sep 2, 2022
    这...不应该是重写个 button 组件注册到全局吗?
    linkopeneyes
        3
    linkopeneyes  
       Sep 2, 2022
    写个插件咯,或者把你的组件库的 button 重写,全局注入,但是也不现实,所有 button 都用一个权限?
    hafuhafu
        4
    hafuhafu  
       Sep 2, 2022
    指令实际上就是操作 dom 完成某种功能吧,既然需要所有的按钮完成某种功能,直接用选择器选中这些元素,剩下和指令里的操作一样吧。至于对应上到指令的参数和修饰符,没做什么特殊的设计,应该是没法动态了。
    chenjiangui998
        5
    chenjiangui998  
       Sep 5, 2022
    你直接说需求是什么吧, 感觉是典型的 AB 问题
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5355 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 46ms · UTC 08:02 · PVG 16:02 · LAX 01:02 · JFK 04:02
    ♥ Do have faith in what you're doing.