-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No conversion from kebab-case to camelCase for property binding #13055
Comments
I think the main problem is the ESLint rule. What happens is, if one has this rule enabled with auto-fix, then the code from valid ( This forces the use of |
the workaround is to add the |
I'm running into a similar problem because of attribute name casing convention, and from what I found, there's a lot of people having similar issues. I found these 2 comments that better describe the issue and point to a possible fix: vuejs/docs#1972 (comment) My specific use case is, I have a Vue component library that wraps a Custom Element library, like for example: class MyElement extends HTMLElement {
...
// Reflect primitive values
get someString() {
return this.getAttribute('some-string');
}
set someString(value) {
if (value) this.setAttribute('some-string, value);
else this.removeAttribute('some-string);
}
// Don't reflect complex objects
get someComplexObject() {
return this._someComplexObject;
}
set someComplextObject(value) {
this._someComplextObject = value;
}
} <script setup lang="ts">
import './MyElement.js';
defineProps<{
someString: string;
someComplexObject: Record<string, string>;
}>();
</script>
<template>
<my-element :some-string :some-complex-object></my-element>
</template> In this example, the <my-element some-complex-object="[object Object]"></my-element> So the alternatives are:
None of these seem very appealing to me. Since Vue does already case conversion in a lot of places, why not here as well to make our lifes easier? I'm assuming that changing: core/packages/runtime-dom/src/patchProp.ts Line 143 in e16e9a7
to: return camelize(key) in el || key in el; would fix this issue without introducing any breaking changes. I'm happy to open a PR if that would be an acceptable solution. |
@vonBrax PR welcome! |
Vue version
3.5.13
Link to minimal reproduction
https://github.com/padcom/vue-property-mapping-bug
Steps to reproduce
npm install
npm start
What is expected?
When dot-binding to a property the conversion from kebab-case to camelCase should happen just as well as when it is with
v-bind
-ing attributes.There is an ESLint rule (
vue/attribute-hyphenation
) that has no separate configuration for prop vs attr binding, which makes me assume both should work the same.What is actually happening?
When binding using property binding with a
.test-prop
the actual assigned property istest-prop
instead oftestProp
as it would be with attribute binding.System Info
Any additional comments?
I am not sure how this should be handled. There are at least two options:
The text was updated successfully, but these errors were encountered: