html部分
<div :class=""getSxxClass(item) v-for="(item,index) in data.sxxList" :key="index" @click="sxxchangeQuery(item)"></div>
js部分
const data = reactive({
sxxList:[
{name:"重庆",id:'1'},
{name:"四川",id:'2'},
{name:"广西",id:'3'},
],
sxx:[],
})
const sxxchangeQuery = (val) => {
let ids = data.sxx.filter(item => {
return item;
})
if(ids.includes(val.id)){
data.sxx = data.sxx.filter(item => {
return item !== val.id
})
} else {
data.sxx.push(val.id)
}
}
const getSxxClass = (val) => {
return data.sxx.filter(item => {
return item === val.id
}).length > 0 ? 'active':'auther'
}
标签:vue,return,多选,自定义,item,val,sxx,data,id From: https://www.cnblogs.com/tanchangsha/p/17119807.html