Skip to content

Commit

Permalink
fix: 修复 addStyle方法报错customStyle.forEach is not a function的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
LynasTing committed Sep 10, 2024
1 parent 35678a0 commit fa39568
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/uni_modules/uview-plus/libs/function/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,16 @@ export function addStyle(customStyle, target = 'object') {
}
// 这里为对象转字符串形式
let string = ''
if (typeof customStyle === 'object') {
customStyle.forEach((val, i) => {
// 驼峰转为中划线的形式,否则css内联样式,无法识别驼峰样式属性名
const key = i.replace(/([A-Z])/g, '-$1').toLowerCase()
string += `${key}:${val};`
if (Object.prototype.toString.call(customStyle) === '[object Object]') {
// customStyle.forEach((val, i) => {
// // 驼峰转为中划线的形式,否则css内联样式,无法识别驼峰样式属性名
// const key = i.replace(/([A-Z])/g, '-$1').toLowerCase()
// string += `${key}:${val};`
// })
Object.entries(customStyle).forEach(([key, val]) => {
// 驼峰命名转换为中划线
key = key.replace(/([A-Z])/g, '-$1').toLowerCase()
string += `${key}: ${val};`
})
}
// 去除两端空格
Expand Down

0 comments on commit fa39568

Please sign in to comment.