经实验,如下似乎在wxss中不支持全局变量哇???
:root { --primary-color: #167075;}.some-text { color: var(--primary-color)}/* # 外部引入方式(不支持?) *//* variables.wxss */:root { --primary-color: red;} /* app.wxss */@import "./variables.wxss";.some-text { color: var(--primary-color)}/* # 局部声明(的确是支持的) */.some-text { --primary-color: red; color: var(--primary-color)
|
--这样子就很尴尬。。。

变量是支持的,但是 :root 选择器不支持。目前支持的选择器可以参考 https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxss.html#%E9%80%89%E6%8B%A9%E5%99%A8
o98k
换用page即可
/* variables.wxss */ page { --primary-color: red; } /* app.wxss */ @import"./variables.wxss"; .some-text { color: var(--primary-color); /* OK */ }放在app也行
/* app.wxss */ page { --secondary-color: blue; } /* pages/some-page/index.wxss */ /* app.wxss are global styles that apply to each page */ .some-text { color: var(--secondary-color); /* OK */ }