Skip to content

fix(vue-common): compatible with camel case format and mutton string format of transferred attributes, optimized attribute overwriting logic #3427

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

Merged
merged 1 commit into from
May 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/vue-common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,14 @@ export const $setup = ({ props: propData, context, template, extend = {} }) => {
const customProps = getCustomProps()

Object.keys(designProps).forEach((key) => {
// 传递的属性可能是羊肉串格式也有可能是驼峰格式,需要兼容两种写法
const camelKey = key.replace(/-(\w)/g, (_, c) => c.toUpperCase())
const kebabKey = key.replace(/([A-Z])/g, '-$1').toLowerCase()
// 用户没有配置的属性才进行覆盖
if (!Object.prototype.hasOwnProperty.call(customProps, key)) {
if (
!Object.prototype.hasOwnProperty.call(customProps, camelKey) &&

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new logic ensures compatibility with both camel case and kebab case formats for attributes. This change prevents overwriting user-configured attributes by checking both formats before proceeding.

!Object.prototype.hasOwnProperty.call(customProps, kebabKey)
) {
customDesignProps[key] = designProps[key]
}
})
Expand Down
Loading