Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue.js v-bind modifier .camel: fail to covert to camelCase

Tags:

vue.js

I am new to Vue.js and have a basic question.

I use the modifier .camel and try to convert the attribute name "data-abc-def" (kebab-case) to "dataAbcDef"(camelCase), but the result I get is "dataabcdef", i.e., this string is in lowercase, not camelCase.

Following is the code snippet.

<div id="app">
  <a href="#" :data-abc-def.camel="id">${ text }</a>
</div>

var vm = new Vue({
  el: '#app',
  data: {
    text: 'Hello World!',
    id: '123456789!'
  }
});

And the result I get...

enter image description here

like image 871
Cythilya Avatar asked Apr 20 '17 14:04

Cythilya


1 Answers

.camel cannot be applied to arbitrary attributes, which data-* attributes are (it works with SVG's viewBox attribute; see this demo).

See this comment by Vue.js creator on an old issue, stating that:

Hmm, this is annoying because HTML parsing only preserves the camelCase for valid camelCase attributes […]

By the way, this was the issue that initiated the whole .camel feature.

In a later issue response, he says:

Avoid using camelCase when using in-DOM templates.

like image 193
Eliran Malka Avatar answered Nov 15 '22 11:11

Eliran Malka