一、定义变量
data() {
return {
myColor:"#2a9efb",
};
},
二、在templete中激活
<template>
<div class="chat-message" :style="{'--myColor':myColor}">
测试数据
</div>
</template>
三、在css中使用
.chat-message {
background: var(--myColor);
}
微信扫一扫
data() {
return {
myColor:"#2a9efb",
};
},
<template>
<div class="chat-message" :style="{'--myColor':myColor}">
测试数据
</div>
</template>
.chat-message {
background: var(--myColor);
}
相关推荐