scss使用data变量定义样式正常情况:
<template>
<view>
<view class='box :style='styleCss'>aaa</view>
</view>
</template>
data() {
return {
StyleCss: {
'--width': '100rpx',
'--height': '100rpx',
}
}
}
.box {
width: var(--width);
height: var(--height);
}
当你配置完后会发现小程序毫无反应,其他端正常,选择box节点时会发现style={object}
这个时候就需要我们手动怼css行内样式了,具体如下:
<template>
<view>
<view class='box :style="'--width:' + width +';--height:' + height">aaa</view>
</view>
</template>
这样scss中使用就生效了
文章讲述了在Vue小程序中使用SCSSdata变量定义样式时遇到的问题,如何在样式不生效的情况下转为行内样式,以及如何手动设置以使SCSS变量生效。
2199

被折叠的 条评论
为什么被折叠?



