Vue: Warn if colon shorthand is used on v-if/v-html/etc.

Created on 25 Jun 2019  路  7Comments  路  Source: vuejs/vue

What problem does this feature solve?

I just spent way too long debugging something really weird until I realized I accidentally wrote :v-if instead of v-if.

A warning when wrongly using shorthands like : on "native" vue attributes could prevent this bad experience easily.

What does the proposed API look like?

:v-if="foo"

--> console.warn("You specified v-bind:/ v-on: or a corresponding shorthand on a Vue attribute like v-if or similar. Usually this does not make sense.)

contribution welcome feature request good first issue has PR warnings

Most helpful comment

I've seen this happen so often when teaching Vue that even though having a prop named vIf is technically valid, I think this warning would help much more people than ever hurt

All 7 comments

I've seen this happen so often when teaching Vue that even though having a prop named vIf is technically valid, I think this warning would help much more people than ever hurt

Yes. If you wanted a prop, why should have the same name as a v-attribute. That'd be incredibly confusing.

<ConfusingComponent 
  v-if="true"
  :v-if="false"
/>

I'll take this on. It'll be my first issue here.

Thanks but as the tag suggest there is already a Pull request for this

涔犳儻灏卞ソ

@simonhermann

I was going to give it a go but it seems there's a super old PR for this already

Was this page helpful?
0 / 5 - 0 ratings