1.first-child 1).判断是否该标签是否有使用first-child类的 2).在样式中添加一个.text_first_child(如何命名)与内容 3).在该标签中加入index == 0 ? 'text_first_child':''
<template>
<div>
<text class="['text',index == 0 ? 'text_first_child':'']" v-for="(item,index) in lists">
{{item}}
</text>
</div>
</template>
<script>
export default {
data:function () {
return {
lists:[
'hello1',
'hello2',
'hello3',
'hello4',
],
}
}
}
</script>
<style scoped>
.text{
font-size: 20px;
}
/*.text:first-child{
color: red;
}*/
.text_first_child{
color: red;
}
</style>