vue v-for出来的列表,点击当前,当前被点击的字体变颜色(:class)
源码:<template><div><div v-for="(item , index) in semesterSelection" @click="changSemester(index)" :key="index":class="{blue:i===index}"><p>{{ item.na...
·
源码:
<template>
<div>
<div v-for="(item , index) in semesterSelection" @click="changSemester(index)" :key="index"
:class="{blue:i===index}">
<p>{{ item.name }}</p>
</div>
</div>
</template>
<script>
export default {
data() {
return {
semesterSelection: [
{name: 'xyz'},
{name: 'lm'}
],
i: 0
}
},
methods: {
//点击改变文字颜色
changSemester(index) {
this.i = index;
}
},
}
</script>
<style scoped>
/*点击文字变颜色*/
.blue {
color: blue;
}
</style>
更多推荐
已为社区贡献7条内容
所有评论(0)