uni-app中view实现多选,点击选中并改变样式,再点击取消

效果图:

template:  

<view :class="{'cur': rSelect.indexOf(index)!=-1}" v-for="(value,index) in infoArr" :key="index" @tap="tapInfo(index)">{{value.name}}</view>

  js:

export default {
    data(){
        return{
            rSelect:[]
        }
    },
    methods:{
        tapInfo(e) {
	        if (this.rSelect.indexOf(e) == -1) {
	    	    console.log(e)//打印下标
		        this.rSelect.push(e);//选中添加到数组里
	        } else {
		        this.rSelect.splice(this.rSelect.indexOf(e), 1); //取消
		    }
        }
    }
}

css(选中样式):

.cur {
		color: white;
		border: 1px solid #e5e5e5;
		background-color: #ff5d00;
}

猜你喜欢

转载自blog.csdn.net/qq_40476712/article/details/103424071