Vue: Should I use "&" or "&" if I am passing in a string as a prop?

Viewed 391

I have a handful of string props I am passing in from a parent component. Is it best practice to use & or &?

<ChildComponent
    newString="Look & Talk" // or "Look &amp; Talk" ??
>
</ChildComponent>
1 Answers

The answer should be found in ChildComponent:

  • the newString will be rendered as a safe string? then you can go with "Look & Talk"
  • the newString will be user with v-html directive? then you should go with "Look &amp; Talk"

Aaron pointed that & is a logical operator in javascript, but this will only be a problem if you bind the value (:newString or v-bind:newString)

Related