Skip to content

Commit

Permalink
Merge pull request #507 from LynasTing/master
Browse files Browse the repository at this point in the history
fix: 修复 addStyle方法报错customStyle.forEach is not a function的bug
  • Loading branch information
ijry authored Sep 11, 2024
2 parents 35678a0 + fa39568 commit d7d5604
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 d7d5604

Please sign in to comment.