我想根据arr数组里面的item => color数组的state的值来设置active类名,如果color数组的里面元素的state值都为1,则active为true
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.list li {
color: bisque;
}
.list li.active {
color: blueviolet;
}
</style>
</head>
<body>
<div id="app">
<ul class="list">
<li :class="{'active': item.status == 1}" v-for="item in arr" :key="item.id">
<p>{{item.color}}</p>
<p>{{ item.name }}</p>
</li>
</ul>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script>
var app = new Vue({
el: '#app',
data: {
arr: [
{
id: 0,
name: '11111',
status: 0,
color: [
{
text: 'wewee',
state: 0
},
{
text: 'wewee',
state: 1
},
]
},
{
id: 1,
name: '2222',
status: 1,
color: [
{
text: 'wewee',
state: 0
},
{
text: 'wewee',
state: 1
},
]
},
{
id: 2,
name: '3333',
status: 1,
color: [
{
text: 'wewee',
state: 0
},
{
text: 'wewee',
state: 0
},
]
},
{
id: 3,
name: '4444',
status: 0,
color: [
{
text: 'wewee',
state: 1
},
{
text: 'wewee',
state: 1
},
]
}
]
}
})
</script>
</body>
</html>
如果arr数组的某一项中,color数组中每一项的state都为1,则选中.求大神!!!
{'active': item.color.every(item => item.status === 1)}