3

I'm new to Vue and asking myself why I often see a : infront of a Vue component attribute?

I use Ionic with with and for example in the starter template I have the following:

<template>
  <ion-page>
    <ion-header :translucent="true">
    ...
  </ion-page>
</template>

Why here is a :? The result will be the same if i remove the :

1
  • The result will be the same if i remove the : Try to access the viewmodel properties without : or write some javascript expression to see the difference. Commented Dec 28, 2020 at 10:31

1 Answer 1

2

: is the shorthand for v-bind: which is binding the javascript variable to the attribute. https://v2.vuejs.org/v2/guide/class-and-style.html

So regarding :translucent="true", boolean value true will be assigned to the translucent attribute. If : is not added (translucent="true"), string "true" will be assigned to translucent attribute, which will also work because any non-empty string will be converted to the true boolean variable internally.

So logically : is needed to assign the boolean value.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.