uni-app 点击切换class

<view class="dl" v-for="(item, index) in items" :key="index" :class="{on: currentIndex === index}" @click="addclass(index)">
	<view class="dt">{{item.txt}}</view>
</view>

<script>
	export default {
		data() {
			return {
				items: [
					{
						txt: '1000元',
					},
					{
						txt: '2000元',
					},
					{
						txt: '3000元',
					},
				],
				currentIndex: '',
				
			}
		},
		methods: {
			addclass(index) {
			    this.currentIndex=index
			}
			
		}
	}
</script>
<style>
.dl{color: #333;}
.dl.on{color: #ff0000;}
</style>
发布日期:
分类:Uniapp

发表评论