Vue directive - passing in string
Asked Answered
V

0

7

I have the following custom directive in vue

<h1 v-role="'admin'">Your Dashboard</h1>

It works fine but would be cleaner without the single quotes. Is this possible?

  <h1 v-role="admin">Your Dashboard</h1>
Vernita answered 28/6, 2018 at 11:5 Comment(6)
Is admin a model? If so bind it <h1 :v-role="admin">Your Dashboard</h1>Beulahbeuthel
it's not. I think i have to live with itVernita
You could think of using constants and then go like <h1 v-role="ROLES.ADMIN"> Your Dashboard</h1>. However this is question of preference.Stylographic
@DF Thanks - is an interesting idea, don't know if I like it any more than strings.Vernita
in vuejs 2.*, you can define your custom directive to use binding.expression instead of binding.value. Hope it helps.Newly
@SasanFarrokh it works, but vue throws and error "Property or method 'X' is not defined on the instace but referenced during render."Batton

© 2022 - 2024 — McMap. All rights reserved.