uniapp给循环列表点击toggle class类名切换

<view class="li" v-for="(item, index) in list" :key="index" :class="{on: currentIndex === index}" @click="toggleClass(index)">
    {{item.txt}}
</view>
export default {
    data() {
        return {
            list: [
                { txt: '选项1' },
                { txt: '选项2' },
                { txt: '选项3' },
                { txt: '选项4' },
                { txt: '选项5' },
            ],
            currentIndex: '',
        }
    },
    methods: {
        toggleClass(index) {
            this.currentIndex = this.currentIndex === index ? -1 : index;
        }
			
    }
发布日期:
分类:Uniapp

发表评论