今天在别人的代码中发现 vue 的 css 代码中居然可以使用 state,挺神奇的,记录一下,代码如下
<template>
<p class="text">法外狂徒张三</p>
</template>
<script>
export default {
data() {
return {
color: 'red',
fontSize: '50',
}
},
mounted() {
setInterval(() => {
this.color = Math.random() > 0.5 ? 'red' : 'blue'
}, 1000)
},
}
</script>
<style>
.text {
color: v-bind(color);
font-size: v-bind(fontSize + 'px');
}
</style>