You have to use v-bind or : syntax to pass data from the parent scope to your component's scope.
If you omit them and just use spacer="true" Vue will interpret your spacer prop as the string "true" and not the boolean true.
Props without values (think attributes) in Vuejs
Hey guys,
I was wondering if it's possible to do something like this in Vue
<div spacer>
</div>
That would achieve the same result as
<div :spacer="true">
</div>
So basically I need to know if we can have attribute like syntax in Vue where we can detect the usage / presence of a prop instead of having verbose syntax like above.
Any help is much appreciated !
Thanks in advance :)
@jimmck I know that but that's not what I was asking :) Anywhoo, I found the answer I was looking for; did a little digging through the source code. So for anyone with a use-case similar to mine, here's the solution.
First off, here's the requirement :
<div my-custom-attribute></div>
Notice how I'm not using v-bind or :my-custom-attribute="value". If you would like to look for the "presence" of a custom attribute, here's how. On your Vue instance, you can access attributes like so :
this.$el.attributes
This will give you a 0-based index array of attributes specified on the element. Now that we have our attributes array, we can fetch the one we need, for example my-custom-attribute like so :
this.$el.attributes.getNamedItem('my-custom-attribute')
Now that we know how to detect / find our attributes, we can do any computation with it.
Please or to participate in this conversation.