vuejs / vue

This is the repo for Vue 2. For Vue 3, go to https://github.com/vuejs/core
http://v2.vuejs.org
MIT License
208.07k stars 33.69k forks source link

Vue treat every element attribute named like 'v-[something]' as directive #8733

Open mcekiera opened 6 years ago

mcekiera commented 6 years ago

Version

2.5.17

Reproduction link

http://jsfiddle.net/wf48v9de/3/

Steps to reproduce

Run the fiddle and look at console.

What is expected?

If there is not registered directive named 'v-fake', Vue should ignore this attribute of an element.

What is actually happening?

Vue treat every 'v-[something]' attribute as directive, regardless if it is registered globally or locally, or not at all. It is trying to compute the value of 'v-' beginning attribute, and in effect throws TypeError, as it doesn't find property named like string passed to attribute.


if it is intentional, there should be information about such behavior in Vue docs. However in my opinion it should ignore such attributes.

kayandra commented 6 years ago

IMHO, I think the docs are clear enough. The v-* lookup has a good behavior. It makes debugging easier, if you want to add a property v-something and not want Vue to treat it as a directive, you should be using data attributes

So instead of <div v-fake/> it should be <div data-v-fake/>

posva commented 6 years ago

Maybe it would make more sense to resolve the directive and show an error (like when there is no value)

kayandra commented 6 years ago

@posva I guess that could work.