Description
I now understand that when passing props to components the HTML attributes must be kebob-case such as <my-component my-prop="abc"></my-component>
At the same time, in Javascript props may be (should be?) named in camelCase such as prop: ['myProp']
and must be referenced in JavaScript via camelCase such as x = this.myProp
The documentation at https://vuejs.org/v2/guide/components-props.html isn't quite clear about this with respect to passing values to props when using components.
I think adding a line to the documentation would have saved me several hours of debugging today. How about:
Prop Casing (camelCase vs kebab-case)
HTML attribute names are case-insensitive, so browsers will interpret any uppercase characters as lowercase. That means when you’re using in-DOM templates, camelCased prop names need to use their kebab-cased (hyphen-delimited) equivalents:
This also means that when using components you must pass values via kebab-case attributes, even if the prop name is defined in camelCase. Vue will automatically know that an HTML attribute like
<blog-post post-title="hello!"></blog-post>
is to be accessed asthis.postTitle
within JavaScript code.
The clarification about remembering to pass prop as kebab-case even though the prop is defined as camelCase would have been helpful. Also, the clarification that Vue automatically allows the kebab-case prop to be accessed in in JavasScript as a camelCase identifier would likewise have helped me more quickly understand the behavior.