1. UniApp 解决 style 绑定 css 变量,支持 var() 使用
参考文章:developer.aliyun.com/article/129…
定义变量
let varStyle = ref('');
varStyle.value = "--bgcolor: yellow;--base: " + (row.value > 9 ? '2.4' : '2') + ";--row: " + row.value + ";--col: " + col.value;
绑定
<div id="root" :style="varStyle">
样式:
#root {
width: calc(var(--col) * 42px + 200px);
}
#game {
grid-template-rows: repeat(var(--row), calc(84px / var(--base)));
grid-template-columns: repeat(var(--col), calc(84px / var(--base)));
}