Skip to content

Commit f9d88bc

Browse files
authored
fix($setup): 兼容处理传递属性的驼峰格式和羊肉串格式,优化属性覆盖逻辑 (#3427)
1 parent 9925d31 commit f9d88bc

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

packages/vue-common/src/index.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,14 @@ export const $setup = ({ props: propData, context, template, extend = {} }) => {
189189
const customProps = getCustomProps()
190190

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

0 commit comments

Comments
 (0)