From b246555c352170c2c36b6a117deaa7e8a30e94cc Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Fri, 23 Sep 2022 17:46:42 +0800 Subject: [PATCH] fix: v-bind in CSS support rpx (#3884) --- .../src/view/framework/dom/components/UniComponent.ts | 3 ++- .../uni-app-plus/src/view/framework/dom/elements/UniElement.ts | 3 ++- packages/uni-h5-vue/dist/vue.runtime.esm.js | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/uni-app-plus/src/view/framework/dom/components/UniComponent.ts b/packages/uni-app-plus/src/view/framework/dom/components/UniComponent.ts index 3bd3aac81..46bc834c1 100644 --- a/packages/uni-app-plus/src/view/framework/dom/components/UniComponent.ts +++ b/packages/uni-app-plus/src/view/framework/dom/components/UniComponent.ts @@ -29,6 +29,7 @@ import { import { decodeAttr, isCssVar } from '../utils' import { patchVShow, VShowElement } from '../directives/vShow' import { initRenderjs } from '../renderjs' +import { normalizeStyleValue } from '../../../utils' export class UniComponent extends UniNode { declare $: UniCustomElement @@ -131,7 +132,7 @@ export class UniComponent extends UniNode { this.$props.style = newStyle } } else if (isCssVar(name)) { - this.$.style.setProperty(name, value as string) + this.$.style.setProperty(name, normalizeStyleValue(value as string)) } else { value = decodeAttr(this.$ || $(this.pid).$, value) if (!this.wxsPropsInvoke(name, value, true)) { diff --git a/packages/uni-app-plus/src/view/framework/dom/elements/UniElement.ts b/packages/uni-app-plus/src/view/framework/dom/elements/UniElement.ts index 538ca1f62..89f6b1856 100644 --- a/packages/uni-app-plus/src/view/framework/dom/elements/UniElement.ts +++ b/packages/uni-app-plus/src/view/framework/dom/elements/UniElement.ts @@ -23,6 +23,7 @@ import { import { decodeAttr, isCssVar } from '../utils' import { patchVShow, VShowElement } from '../directives/vShow' import { initRenderjs } from '../renderjs' +import { normalizeStyleValue } from '../../../utils' export class UniElement extends UniNode { declare $: UniCustomElement @@ -137,7 +138,7 @@ export class UniElement extends UniNode { if (this.$propNames.indexOf(name) !== -1) { ;(this.$props as any)[name] = value } else if (isCssVar(name)) { - this.$.style.setProperty(name, value as string) + this.$.style.setProperty(name, normalizeStyleValue(value as string)) } else { if (!this.wxsPropsInvoke(name, value)) { this.$.setAttribute(name, value as string) diff --git a/packages/uni-h5-vue/dist/vue.runtime.esm.js b/packages/uni-h5-vue/dist/vue.runtime.esm.js index 51f937f79..31cc90f42 100644 --- a/packages/uni-h5-vue/dist/vue.runtime.esm.js +++ b/packages/uni-h5-vue/dist/vue.runtime.esm.js @@ -10068,7 +10068,7 @@ function setVarsOnNode(el, vars) { if (el.nodeType === 1) { const style = el.style; for (const key in vars) { - style.setProperty(`--${key}`, vars[key]); + style.setProperty(`--${key}`, normalizeRpx(vars[key])); } } } -- GitLab