Skip to content
Advertisement

How to clean up v-bind directives from html code in Vue?

Ok, I’ve got some Vue code and HTML.

For example:

JavaScript

And in my page:

JavaScript

It all works, but if I read the page source, I see the v-bind:selects="selects" portion, which is not standard compliant, I guess.

Similarly, other components have other object properties like:

JavaScript

which on the page source evaluates to something like:

JavaScript

which is obviously not desirable.

How do I bind these properties without them appearing in the DOM as attributes?

Advertisement

Answer

My own answer is: pass props when you call the component, not in the component itself. This code will work and produce clean html:

In-page HTML:

JavaScript

JS:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement