From fa3956836da8c18cb2c783c0c82dd3f3d3388bee Mon Sep 17 00:00:00 2001 From: LynasTing Date: Tue, 10 Sep 2024 21:39:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20addStyle=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E6=8A=A5=E9=94=99customStyle.forEach=20is=20not=20a?= =?UTF-8?q?=20function=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/uni_modules/uview-plus/libs/function/index.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/uni_modules/uview-plus/libs/function/index.js b/src/uni_modules/uview-plus/libs/function/index.js index d9593f545..fcbe894d2 100644 --- a/src/uni_modules/uview-plus/libs/function/index.js +++ b/src/uni_modules/uview-plus/libs/function/index.js @@ -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};` }) } // 去除两端空格