<div style="color: #f40;">hi,there</div> <div style="fontSize: 20px">hi,there</div> <div style="font-size: 20px">hi,there</div> <div style="background-color: #f40;">hi,there</div> <div style="backgroundColor: #f40;">hi,there</div>
绑定的是值 value
为了和绑定的数据|样式值区分,建议:key 使用引号括起来
<div :style="{ 'color': txtColor }">hi,there</div>
<div :style="{ 'background-color': color }">content</div>
<div :style="{ 'backgroundColor': color }">content</div>
<div :style="{ 'fontSize': small + 'px' }">hi,there</div>
<div :style="`font-size: ${small}px`">hi,there</div>
//模板字符串不支持小驼峰写法!!!
<div :style="`fontSize: ${small}px`">hi,there</div>//x
<div :style="{ 'backgroundColor': color, 'lineHeight': h + 'px' }">content</div>
<nav class="nav">
<div class="item" @click="navInd = 0">Lorem.</div>
<div class="item" @click="navInd = 1">Neque?</div>
<div class="item" @click="navInd = 2">Incidunt.</div>
<div class="item" @click="navInd = 3">Quidem!</div>
<div class="line" :style="{ '--ind': navInd }"></div>
</nav>
import { ref } from 'vue'
const navInd = ref(0)
// 其它样式
.line {
position: absolute;
left: 0;
bottom: 0;
width: 80px;
height: 2px;
background: #f40;
transform: translateX(calc(80px * var(--ind)));
transition: 0.5s;
}